WordPress站点出现404错误时邮件通知管理员的方法
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>本文实例讲述了WordPress站点出现404错误时邮件通知管理员的方法。分享给大家供大家参考。具体分析如下:</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
这是一个比较实用的功能,当我们网站出现了错误时就邮箱通知管理员,将下面的代码添加到你所用的WordPress主题的 404.php 文件的顶端即可.</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
如果你的主机支持mail()函数或者设置了SMTP发送邮件,总之就是能够发送邮件就行,一会去查看你设置的WordPress站点的管理员邮箱,你就会发现404通知邮件,可能在垃圾箱哦.</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
实例代码如下:<br>
</p>
<div style='margin: 3px auto 0px; padding: 0px 3px; outline: none; line-height: 21.6px; clear: both; border-width: 1px; border-style: solid; border-color: rgb(0, 153, 204); background: rgb(246, 251, 255); overflow: hidden; font-family: tahoma, arial, "Microsoft YaHei";'>
<div style="margin: 0px; padding: 0px; outline: none; float: right; line-height: 25.2px; font-size: 14px;">
<span style="line-height: 25.2px; cursor: pointer;"><u>复制代码</u></span>
</div>
代码如下:</div>
<div id="phpcode4" style='margin: 0px auto 3px; padding: 0px 3px; outline: none; line-height: 25.2px; font-size: 14px; clear: both; border-right: 1px solid rgb(0, 153, 204); background: rgb(221, 237, 251); overflow: hidden; border-left: 1px solid rgb(0, 153, 204); word-break: break-all; border-bottom: 1px solid rgb(0, 153, 204); word-wrap: break-word; font-family: tahoma, arial, "Microsoft YaHei";'>
mail($email, "404 Alert: " . $blog . " [" . $theme . "]", $message, "From: $email");</div>
<br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>完整代码如下:</span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><div style='margin: 3px auto 0px; padding: 0px 3px; outline: none; line-height: 21.6px; clear: both; border-width: 1px; border-style: solid; border-color: rgb(0, 153, 204); background: rgb(246, 251, 255); overflow: hidden; font-family: tahoma, arial, "Microsoft YaHei";'>
<div style="margin: 0px; padding: 0px; outline: none; float: right; line-height: 25.2px; font-size: 14px;">
<span style="line-height: 25.2px; cursor: pointer;"><u>复制代码</u></span>
</div>
代码如下:</div>
<div id="phpcode5" style='margin: 0px auto 3px; padding: 0px 3px; outline: none; line-height: 25.2px; font-size: 14px; clear: both; border-right: 1px solid rgb(0, 153, 204); background: rgb(221, 237, 251); overflow: hidden; border-left: 1px solid rgb(0, 153, 204); word-break: break-all; border-bottom: 1px solid rgb(0, 153, 204); word-wrap: break-word; font-family: tahoma, arial, "Microsoft YaHei";'>
<?php<br>
// WP 404 ALERTS <br><br>
// set status <br>
header("HTTP/1.1 404 Not Found"); <br>
header("Status: 404 Not Found"); <br><br>
// site info <br>
$blog = get_bloginfo('name'); <br>
$site = get_bloginfo('url') . '/'; <br>
$email = get_bloginfo('admin_email'); <br><br>
// theme info <br>
if (!emptyempty($_COOKIE["nkthemeswitch" . COOKIEHASH])) { <br>
$theme = clean($_COOKIE["nkthemeswitch" . COOKIEHASH]); <br>
} else { <br>
$theme_data = wp_get_theme(); <br>
$theme = clean($theme_data->Name); <br>
} <br><br>
// referrer <br>
if (isset($_SERVER['HTTP_REFERER'])) { <br>
$referer = clean($_SERVER['HTTP_REFERER']); <br>
} else { <br>
$referer = "undefined"; <br>
} <br>
// request URI <br>
if (isset($_SERVER['REQUEST_URI']) && isset($_SERVER["HTTP_HOST"])) { <br>
$request = clean('http://' . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"]); <br>
} else { <br>
$request = "undefined"; <br>
} <br>
// query string <br>
if (isset($_SERVER['QUERY_STRING'])) { <br>
$string = clean($_SERVER['QUERY_STRING']); <br>
} else { <br>
$string = "undefined"; <br>
} <br>
// IP address <br>
if (isset($_SERVER['REMOTE_ADDR'])) { <br>
$address = clean($_SERVER['REMOTE_ADDR']); <br>
} else { <br>
$address = "undefined"; <br>
} <br>
// user agent <br>
if (isset($_SERVER['HTTP_USER_AGENT'])) { <br>
$agent = clean($_SERVER['HTTP_USER_AGENT']); <br>
} else { <br>
$agent = "undefined"; <br>
} <br>
// identity <br>
if (isset($_SERVER['REMOTE_IDENT'])) { <br>
$remote = clean($_SERVER['REMOTE_IDENT']); <br>
} else { <br>
$remote = "undefined"; <br>
} <br>
// log time <br>
$time = clean(date("F jS Y, h:ia", time())); <br><br>
// sanitize <br>
function clean($string) { <br>
$string = rtrim($string); <br>
$string = ltrim($string); <br>
$string = htmlentities($string, ENT_QUOTES); <br>
$string = str_replace("n", "<br>
", $string); <br><br>
if (get_magic_quotes_gpc()) { <br>
$string = stripslashes($string); <br>
} <br>
return $string; <br>
} <br><br>
$message = <br>
"TIME: " . $time . "n" . <br>
"*404: " . $request . "n" . <br>
"SITE: " . $site . "n" . <br>
"THEME: " . $theme . "n" . <br>
"REFERRER: " . $referer . "n" . <br>
"QUERY STRING: " . $string . "n" . <br>
"REMOTE ADDRESS: " . $address . "n" . <br>
"REMOTE IDENTITY: " . $remote . "n" . <br>
"USER AGENT: " . $agent . "nnn"; <br><br>
mail($email, "404 Alert: " . $blog . " [" . $theme . "]", $message, "From: $email"); <br>
?></div>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
希望本文所述对大家的WordPress建站有所帮助。</p>
頁:
[1]