I’m making a plugin that emails the site webmaster when I go to the 404 page. The script checks if the referring link is on our site, and then sends an email to the webmaster.
$message = "
<html>
<head>
<title>Alton Bible Church - Broken Link</title>
<style type="text/css">
* {
font-family:Arial;
}
table {
background:#eee;
padding:15px;
}
#table {
width:500px;
overflow:scroll;
}
td {
border: 1px solid #aaa;
padding:10px;
}
</style>
</head>
<body>
<p>There's a broken link on My Website</p>
<div id="table">
<table>
<tr>
<td>Broken Link</td><td>Referring Link</td>
</tr>
<tr>
<td><a href="" . $broken . "">" . $broken . "</a></td><td><a href="" . $referrer . "">" . $referrer . "</a></td>
</tr>
</table>
</div>
</body>
</html>";
$headers = 'MIME-Version: 1.0' . 'rn';
$headers .= 'Content-type: text/html; charset=iso-8859-1' . 'rn';
$headers .= 'From: My Website <no-reply@mysite.net>' . 'rn';
mail("Webmaster <webmaster@mysite.net>", "My Website - Broken Link", $message, $headers);
The problem is, the email is not being sent. Does WordPress not allow me to use mail()?
The problem shouldn’t be with the server.
Thanks!
Use
wp_mail()
, not justmail()
. It is a wrapper for PHPMailer, a class that takes care for many problems the nativemail()
function often gets.See my plugin 404 Tools for how to use it in this case. To send an HTML email see Miloâs answer to a related question.
wordpress doesn’t block the php
mail()
function. One error that i can see is that'rn'
should be in double quotes like this"rn"
Even though
mail()
works, it’s a good practice to use wordpress functions, herewp_mail()
Just put this in your functions.php and it should be OK.