原本小z博客使用了多说评论,回复对方后会收到多说的提示,不过近期Gravatar头像被墙,多说服务器也太不稳定,部分头像回源而不能缓存,导致博客加载异常缓慢,还没有解决的请看这里。
因此最近又换回了wordpress自带评论,回归简单化,速度感觉提升了不少,不过为了利于用户体验,当别人在我们博客留言我们回复对方的时候希望对方能够收到一条通知,那么就可以使用评论回复邮件通知的功能。
网上提供了很多种代码的方法,我也试过好几种,有的代码已经失效不再起作用,而有的代码则不太完整,最后由热心网友无主题提供了一段不错的功能代码,只需要将代码添加到主题目录的functions.php中即可。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
// 评论回应邮件通知 function comment_mail_notify($comment_id) { $admin_email = get_bloginfo ("admin_email"); $comment = get_comment($comment_id); $comment_author_email = trim($comment->comment_author_email); $parent_id = $comment->comment_parent ? $comment->comment_parent : ""; $to = $parent_id ? trim(get_comment($parent_id)->comment_author_email) : ""; $spam_confirmed = $comment->comment_approved; if (($parent_id != "") && ($spam_confirmed != "spam") && ($to != $admin_email)) { $wp_email = "no-reply@" . preg_replace("#^www.#", "", strtolower($_SERVER["SERVER_NAME"])); $subject = "您在 [" . get_option("blogname") . "] 的留言有了新回复"; $message = " |
显示的效果请看下面的截图,如果你的主机禁用了mail()函数,建议使用WP SMTP插件或使用SMTP代码来解决。

