WordPress免插件实现评论回复邮件提醒

之前的一篇文章主题君介绍了WordPress纯代码免插件配置SMTP邮件功能教程,还不知道如何配置SMTP邮件功能的朋友可以再看一遍这边文章:

[xx_insert_post station_article=”1446″]

今天主题君分享一篇WordPress免插件实现评论回复邮件提醒的教程。

博客上有人评论留言就会自动发邮件提示你,这个功能还是很实用的,

首先将下面代码修改后复制到functions.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 = \\\'no-reply@\\\' . preg_replace(\\\'#^www\\\\.#\\\', \\\'\\\', strtolower($_SERVER[\\\'SERVER_NAME\\\']));//发件人e-mail地址$to = trim(get_comment($parent_id)->comment_author_email);$subject = \\\'您在 [\\\' . get_option(\\\"blogname\\\") . \\\'] 的留言有了回应\\\';$message = \\\'<div style=\\\"border-right:#666666 1px solid;border-radius:8px;color:#111;font-size:12px;width:702px;border-bottom:#666666 1px solid;font-family:微软雅黑,arial;margin:10px auto 0px;border-top:#666666 1px solid;border-left:#666666 1px solid\\\"><div ></div><div style=\\\"width:100{5cc1b29162d549a8071384de182cc9fc6e6a0fd85e7907f22fd9e18cff4269c3};background:#666666;min-height:60px;color:white;border-radius:6px 6px 0 0\\\"><span style=\\\"line-height:60px;min-height:60px;margin-left:30px;font-size:12px\\\">您在<a style=\\\"color:#00bbff;font-weight:600;text-decoration:none\\\" href=\\\"\\\' . get_option(\\\'home\\\') . \\\'\\\" target=\\\"_blank\\\">\\\' . get_option(\\\'blogname\\\') . \\\'</a> 上的留言有回复啦!</span> </div><div style=\\\"margin:0px auto;width:90{5cc1b29162d549a8071384de182cc9fc6e6a0fd85e7907f22fd9e18cff4269c3}\\\"><p>\\\' . trim(get_comment($parent_id)->comment_author) . \\\', 您好!</p><p>您于\\\' . trim(get_comment($parent_id)->comment_date) . \\\' 在文章《\\\' . get_the_title($comment->comment_post_ID) . \\\'》上发表评论: </p><p style=\\\"border-bottom:#ddd 1px solid;border-left:#ddd 1px solid;padding-bottom:20px;background-color:#eee;margin:15px 0px;padding-left:20px;padding-right:20px;border-top:#ddd 1px solid;border-right:#ddd 1px solid;padding-top:20px\\\">\\\' . nl2br(get_comment($parent_id)->comment_content) . \\\'</p><p>\\\' . trim($comment->comment_author) . \\\' 于\\\' . trim($comment->comment_date) . \\\' 给您的回复如下: </p><p style=\\\"border-bottom:#ddd 1px solid;border-left:#ddd 1px solid;padding-bottom:20px;background-color:#eee;margin:15px 0px;padding-left:20px;padding-right:20px;border-top:#ddd 1px solid;border-right:#ddd 1px solid;padding-top:20px\\\">\\\' . nl2br($comment->comment_content) . \\\'</p><p>您可以点击 <a style=\\\"color:#00bbff;text-decoration:none\\\" href=\\\"\\\' . htmlspecialchars(get_comment_link($parent_id)) . \\\'\\\" target=\\\"_blank\\\">查看回复的完整內容</a></p><p>感谢你对 <a style=\\\"color:#00bbff;text-decoration:none\\\" href=\\\"\\\' . get_option(\\\'home\\\') . \\\'\\\" target=\\\"_blank\\\">\\\' . get_option(\\\'blogname\\\') . \\\'</a> 的关注,如您有任何疑问,欢迎在博客留言,我会一一解答</p><p>(此邮件由系统自动发出,请勿回复。)</p></div></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 );//echo \\\'mail to \\\', $to, \\\'<br/> \\\' , $subject, $message; // for testing}}add_action(\\\'comment_post\\\', \\\'comment_mail_notify\\\');

扫码关注wp主题君

精选优质免费WordPress主题模板,分享最新WordPress实用建站教程!

记住我们的网址:ztJun.com

本文来源于 网络,由本站搜集发布,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系本站核实处理。如需转载,请注明文章来源。

© 版权声明
THE END
喜欢就支持一下吧
点赞25 分享