WordPress添加评论回复邮件提醒通知功能

首先去插件—安装—-搜索—–Easy WP SMTP
安装好有。请自行填入。不懂的请在下面留言。
 
 
WordPress默认主题中用户留言评论,如果我们去回复之后,或者我们用户评论的时候也不会自动通知博主的。我们可以添加评论邮件通知,这样可以及时的与用户进行互动。当然,有很多插件可以实现这样的功能,在这篇文章中,老蒋收集到的办法是不用插件,直接在当前主题Functions.php文件中加入代码就可以实现。

/* comment_mail_notify v1.0 by willin kan. (所有回复都发邮件) */
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 = '你的邮箱' . preg_replace('#^www.#', '', strtolower($_SERVER['SERVER_NAME'])); //e-mail 发出点, no-reply 可改为可用的 e-mail.
    $to = trim(get_comment($parent_id)->comment_author_email);
    $subject = '您在 [' . get_option("blogname") . '] 的留言有了回复';
    $message = '
		<div style="background-color:#0088CC;height:35px;line-height:35px;color:#fff;font-weight:bold;padding-left:20px;border-radius:10px 10px 0 0">您在 ['.get_option ("blogname").'] 的留言有了新的回复</div>
		<div style="border:1px solid #0088CC; color:#111;padding:0 20px;color:#686868;">
		<p><span style="color:#CC0000;font-weight:bold">'.trim(get_comment ($parent_id)->comment_author ).'</span>,您好!</p>
		<p>您曾在<span style="color:#CC0000;font-weight:bold">《'.get_the_title ($comment->comment_post_ID ).'》</span>的留言:</p>
		<div style="margin:10px;border:1px solid #dfdfdf;padding:20px;color:#a0a0a0;">'.trim(get_comment ($parent_id)->comment_content ).'</div>
		<p><span style="color:#CC0000;font-weight:bold">'.trim($comment->comment_author ).' </span>给您的回复:</p>
		<div style="margin:10px;border:1px solid #dfdfdf;padding:20px;color:#a0a0a0;">'.trim($comment->comment_content ).'</div>
		<p>您可以点此 <a href="'.get_permalink ($comment->comment_post_ID ).'" style="text-decoration:none;color:#6A0888;;">→→查看回复的完整內容</a></p>
		<p>欢迎您再度光临:<a href="'.get_option ('home').'" style="text-decoration:none;color:#a0a0a0;;">'.get_option ('blogname').' ( '.get_option ('home').' )</a></p></div>
		<div style="padding:20px;color:#fff;font-size:12px;background-color:#0088CC;border-radius:0 0 10px 10px">请注意:此邮件由[<span style="color:#bbb"> '.get_option ("blogname").'</span> ]自动发送,请勿回复<br>如果此邮件不是您请求的,请忽略并删除!
        </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');
// -- END ----------------------------------------

最终样板::::