in most cases,We are accustomed to using the built-in WordPress commenting system,Although it's not intended to make people - after all,,Third-party commenting system it is difficult to accept。
Relatively good third party to say it is disgusting;The foreign system several good reviews and very inconvenient to use China,In general,Or WordPress comment system comes with the best。
Then,Speaking WordPress comes with this comment system,E-mail notification may be its most important characteristic of the。Although Externally WordPress will not comment publicly on those e-mail address,But you would never think someone would use to notify the proliferation of spam comments it!
Background - Settings - discussions,Check”Comments must be approved by artificial”,All such comments must be reviewed by an administrator to display。
I just need to reply to any comments WordPress site can be friends! and so,We need to stop this behavior,The easiest way is to open only after a review by the audit rather than directly through。Other,We also need to customize the look WordPress comes with e-mail notification function,It smarter - such as other people's comments when someone comments,Only reviewed by the e-mail notification will be issued。
Same,I recommend that you make changes in the sub-theme,So your subject can freely upgrade to avoid self-defined content is cleared out:)
In your current theme functions.php Append the following:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
/** * WordPress评论回复邮件提醒防垃圾评论版 * 作者:露兜 * 博客:http://www.ludou.org/ * * 2014年7月5日 : * 首个版本 */ function ludou_comment_mail_notify($comment_id, $comment_status) { // 评论必须经过审核才会发送通知邮件 if ($comment_status !== 'approve' && $comment_status !== 1) return; $comment = get_comment($comment_id); if ($comment->comment_parent != '0') { $parent_comment = get_comment($comment->comment_parent); // 邮件接收者email $to = trim($parent_comment->comment_author_email); // 邮件标题 $subject = '您在[' . get_option("blogname") . ']的留言有了新的回复'; // 邮件内容,自行修改,支持HTML $message = ' <p>Hi, ' . $parent_comment->comment_author . '</p> <p>您之前在《' . get_the_title($comment->comment_post_ID) . '》的留言:<br />' . $parent_comment->comment_content . '</p> <p>' . $comment->comment_author . ' 给您回复:<br />' . $comment->comment_content . '<br /><br /></p> <p>您可以 <a href="' . htmlspecialchars(get_comment_link($comment->comment_parent)) . '">点此查看回复完整內容</a></p> <p>欢迎再度光临 <a href="'.home_url().'">' . get_option('blogname') . '</a></p> <p>(此邮件由系统自动发送,请勿回复)</p>'; $message_headers = "Content-Type: text/html; charset=\"".get_option('blog_charset')."\"\n"; // 不用给不填email的评论者和管理员发提醒邮件 if($to != '' && $to != get_bloginfo('admin_email')) @wp_mail($to, $subject, $message, $message_headers); } } // 编辑和管理员的回复直接发送提醒邮件,因为编辑和管理员的评论不需要审核 add_action('comment_post', 'ludou_comment_mail_notify', 20, 2); // 普通访客发表的评论,等博主审核后再发送提醒邮件 add_action('wp_set_comment_status', 'ludou_comment_mail_notify', 20, 2); |
optimization
Ok,Now that we have changed the default e-mail notification function,Why not change the way some of the more radical,It looks more pleasing that? In short,I just found some code online beautification,of course,The old code is not run properly,I am referring to the pandanus blog's code of minor modifications,You can take a try:)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
/** * 修复 WordPress 邮件评论回复通知被恶意利用的问题 logcg.com 落格博客 */ function logcg_comment_mail_notify($comment_id, $comment_status) { // 评论必须经过审核才会发送通知邮件 if ($comment_status !== 'approve' && $comment_status !== 1) return; $comment = get_comment($comment_id); if ($comment->comment_parent != '0') { $parent_comment = get_comment($comment->comment_parent); // 邮件接收者email $to = trim($parent_comment->comment_author_email); // 邮件标题 $subject = '您在[' . get_option("blogname") . ']的留言有了新的回复'; // 邮件内容,自行修改,支持HTML $message = ' <div style="background-color:#fff; border:1px solid #666666; color:#111; -moz-border-radius:8px; -webkit-border-radius:8px; -khtml-border-radius:8px; border-radius:8px; font-size:12px; width:702px; margin:0 auto; margin-top:10px; font-family:苹方,微软雅黑, Arial;"> <div style="background:#666666; width:100%; height:60px; color:white; -moz-border-radius:6px 6px 0 0; -webkit-border-radius:6px 6px 0 0; -khtml-border-radius:6px 6px 0 0; border-radius:6px 6px 0 0; "> <span style="height:60px; line-height:60px; margin-left:30px; font-size:12px;"> 您在 <a style="text-decoration:none; color:#00bbff;font-weight:600;" href="' . get_option('home') . '">' . get_option('blogname') . ' </a> 的留言有了新回复!</span></div> <div style="width:90%; margin:0 auto"> <p>' . $parent_comment->comment_author . ',您好!</p> <p>您曾在 [' . get_option("blogname") . '] 的文章 《' . get_the_title($comment->comment_post_ID) . '》 上发表评论: <p style="background-color: #EEE;border: 1px solid #DDD; padding: 20px;margin: 15px 0;">' . nl2br($parent_comment->comment_content) . '</p> <p>' . trim($comment->comment_author) . ' 给您的回复如下: <p style="background-color: #EEE;border: 1px solid #DDD;padding: 20px; margin: 15px 0;">' . nl2br($comment->comment_content) . '</p> <p>您也可移步 <a style="text-decoration:none; color:#00bbff" href="' . htmlspecialchars(get_comment_link($comment->comment_parent)) . '">落格博客</a> 以查看回复的完整內容。</p> <p>欢迎再次光临 <a style="text-decoration:none; color:#00bbff" href="' . get_option('home') . '">' . get_option('blogname') . '</a></p> <p>(此邮件由系统自动发出, 请勿回复。)</p> </div> </div>'; $message_headers = "Content-Type: text/html; charset=\"".get_option('blog_charset')."\"\n"; // 不用给不填email的评论者和管理员发提醒邮件 if($to != '' && $to != get_bloginfo('admin_email')) @wp_mail($to, $subject, $message, $message_headers); } } // 编辑和管理员的回复直接发送提醒邮件,因为编辑和管理员的评论不需要审核 add_action('comment_post', 'logcg_comment_mail_notify', 20, 2); // 普通访客发表的评论,等博主审核后再发送提醒邮件 add_action('wp_set_comment_status', 'logcg_comment_mail_notify', 20, 2); |
effect
At last,Let's look at the results:
Original article written by LogStudio:R0uter's Blog » Optimization of WordPress comment reply notifications
Reproduced Please keep the source and description link:https://www.logcg.com/archives/1638.html
Pretty good,The use of
Okami,Simple atmospheric blog theme。。Send e-mail using the plug-wp SMTP deployment,General themes or messages sent are optimized interface
Support mail()Function under circumstances still not receive mail
Try to use third-party e-mail service,smtp,If your server does not support e-mail,In any case you are unable to go,Service providers need to send work orders to seek further support。
After opening mail notification,Send comments feel a bit slow。
QQ E-mail,Unable to pronounce the letter ah。
When STMP plug-alone test is to be sent successfully。
Turn on encryption ssl?
666
Spend the,thank!
I changed the topic under….Dark colors do not like n
/**
* Repair WordPress Comments Reply Mail notification malicious use problems logcg.com drop off Gerber
* Secondary modify mikifuns blog.mikifuns.com
*/
function logcg_comment_mail_notify($comment_id, $comment_status) {
// Comments must be sent via e-mail notification will be reviewed
if ($comment_status !== ‘approve’ && $comment_status !== 1)
return;
$comment = get_comment($comment_id);
if ($comment->comment_parent != ‘0’) {
$parent_comment = get_comment($comment->comment_parent);
// Mail Recipient email
$to = trim($parent_comment->comment_author_email);
// mail title
$subject = 'You[‘ . get_option(“blog names”) . ‘]With the new reply message ';
// content of email,Amend its own,Support HTML
$message = ‘
You ‘ . get_option("Blogname") . ‘ With the new message reply!
‘ . $parent_comment->comment_author . ‘,Hello!
You had [‘ . get_option(“blog names”) . ‘] Articles
《’ . get_the_title($comment->comment_post_ID) . Comment '' on the:
‘ . nl2br($parent_comment->comment_content) . ‘
‘ . trim($comment->comment_author) . ‘ Give your reply below:
‘ . nl2br($comment->comment_content) . ‘
comment_parent)) . ‘” target=”_self” style=”text-decoration: none;”> Click to view
Welcome again ‘ . get_option("Blogname") . ‘
(This message is automatically issued by the system, Please do not reply directly。)
miki.acg
‘;
$message_headers = “Content-Type: text/html; charset=””.get_option(‘blog_charset’).”\”\n”;
// Do not fill to email comments and send an email alert administrators
if($to != ” && $to != get_bloginfo('ADMIN_EMAIL'))
@wp_mail($to, $subject, $message, $message_headers);
}
}
// Edit and administrators reply directly send reminder emails,Because editors and administrators do not need to review comments
add_action(‘comment_post’, ‘logcg_comment_mail_notify’, 20, 2);
// Regular visitor comments,Bloggers and other review before sending an email alert
add_action(‘wp_set_comment_status’, ‘logcg_comment_mail_notify’, 20, 2);
I Tencent Mail and GMail's SMTP mail is failed login log,Host's own mail system directly Tencent put the trash,gmail directly back letter。。。。
You need to enable ssl encryption,465 port also changed encrypted like,I did not remember hehe,If gmail, then remember to use one-time password,Do not open or step verification。There is chaos filled sender mailbox can not,Your account must be consistent with the job。
Wait to play,You'd work fine,Yesterday I played for a long time are the login fails
correct,What do you use a mailbox
My e-mail on behalf of the mailbox is the QQ mail domain mail,I have a gmail,Now all forwarding hotmail - because this has not yet been Wall:)
Haha,I have a third-party mail this debugging experience,Because I have a website in another fiddle for a long time。
I also tried the Post Tencent enterprise the same error,2016-03-29 13:58:05 SERVER -> CLIENT: 221 Bye
2016-03-29 13:58:05 Connection: closed
2016-03-29 13:58:05 SMTP Error: Could not authenticate.
From Email
To manually verify at the click ssl authentication,The default is not。
Changed the plug was finally able to close GMAIL ah ah ah ah ah,Thanks,Tomorrow plus auto reply
Give praise,This interface looks good,So will I also get back with?