本文作者:admin | 2024-05-31 |
<p>想收到新评论时给站长发邮件,首先得你主机支持邮件接收,并且是否已经开启过?</p> <p>然后在你的主题文件functions.php的代码最后添加以下代码</p> <?php
/* 评论邮件通知 */
function comment_mail_notify($comment_id){
$comment = get_comment($comment_id);
$parent_id = $comment->comment_parent ? $comment->comment_parent : '';
$spam_confirmed = $comment->comment_approved;
if(($parent_id != '') && ($spam_confirmed != 'spam')){
$wp_email = 'webmaster@' . preg_replace('#^www\.#', '', strtolower($_SERVER['SERVER_NAME']));
$to = trim(get_comment($parent_id)->comment_author_email);
$subject = '你在 [' . get_option(blogname) . '] 的留言有了回应';
$message = '
<div style=background-color:#eef2fa; border:1px solid #d8e3e8; color:#111; padding:0 15px; -moz-border-radius:5px; -webkit-border-radius:5px; -khtml-border-radius:5px;>
<p>' . trim(get_comment($parent_id)->comment_author) . ', 你好!</p>
<p>你曾在《' . get_the_title($comment->comment_post_ID) . '》的留言:<br />'
. trim(get_comment($parent_id)->comment_content) . '</p>
<p>' . trim($comment->comment_author) . ' 给你的回应:<br />'
. trim($comment->comment_content) . '<br /></p>
<p>你可以点击 <a href=' . htmlspecialchars(get_comment_link($parent_id)) . '>查看回应完整内容</a></p>
<p><strong>感谢你对 <a href=' . get_option('home') . ' target=_blank>' . get_option('blogname') . '</a> 的关注,欢迎<a href=' . get_option('home') . '/feed/ target=_blank>订阅本站</a></strong></p>
<p><strong>您可以直接回复此邮件与我联系~</strong></p>
</div>';
$from = From: \ . get_option('blogname') . \ <$wp_email>;
$headers = $from\nContent-Type: text/html; charset= . get_option('blog_charset') . \n;
wp_mail( $to, $subject, $message, $headers );
}
}
add_action('comment_post', 'comment_mail_notify');
?>