我正在制作一个插件,当我转到404页面时,它会向网站管理员发送电子邮件。脚本检查引用链接是否在我们的网站上,然后向网站管理员发送电子邮件。
$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\' . \'\\r\\n\';
$headers .= \'Content-type: text/html; charset=iso-8859-1\' . \'\\r\\n\';
$headers .= \'From: My Website <no-reply@mysite.net>\' . \'\\r\\n\';
mail("Webmaster <webmaster@mysite.net>", "My Website - Broken Link", $message, $headers);
问题是,电子邮件没有被发送。WordPress不允许我使用mail()吗?
问题不应该出在服务器上。
谢谢
SO网友:Jeroen
把这个放在你的函数里。php,应该可以。
//SENDS 404 EMAIL TO ADMIN
function email_admin($location){
$blname=get_option(\'blogname\');
$admemail = get_option(\'admin_email\');
$ipaddress = $_SERVER["REMOTE_ADDR"];
$checkip = "http://www.projecthoneypot.org/ip_".$ipaddress;
$mailhead = "MIME-Version: 1.0\\r\\n";
$mailhead .= "Content-type: text/plain; charset=UTF-8\\r\\n";
$mailhead .= \'From: "\' . $blname . \'" \\r\\n";
$mailsubj= $blname.\': 404 error\';
$mailbody=\'Someone wanted to go to \'.$_SERVER[\'SERVER_NAME\'].$location." but you haven\'t created this page yet. Maybe you can have a look and see if anything needs to be fixed.\\r\\n
Their IP address is: ".$ipaddress."\\r\\n\\nIn case you want to check if these are THE BAD GUYS, you can do it at $checkip";
@mail($admemail,$mailsubj,$mailbody,$mailhead);
}
function mail_me_errors(){
global $wp_query;
$location=$_SERVER[\'REQUEST_URI\'];
if ($wp_query->is_404){
email_admin($location);
}
}
add_action(\'get_header\', \'mail_me_errors\');