一聚教程网:一个值得你收藏的教程网站

最新下载

热门教程

wordpress评论邮件自动通知

时间:2022-06-25 19:00:49 编辑:袖梨 来源:一聚教程网

实现评论邮件自动通知的功能只要把以下代码添加到functions.php即可,此方法仅限于Linux主机使用。

代码如下 复制代码

//评论邮件自动通知
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) && ($comment_author_email == $admin_email)) {
$wp_email = 'no-reply@' . preg_replace('#^www.#', '', strtolower($_SERVER['SERVER_NAME']));
$subject = '您在 [' . get_option("blogname") . '] 的评论有新的回复';
$message = '


' . trim(get_comment($parent_id)->comment_author) . ', 您好!


您曾在 [' . get_option("blogname") . '] 的文章 《' . get_the_title($comment->comment_post_ID) . '》 上发表评论:
'
. nl2br(get_comment($parent_id)->comment_content) . '


' . trim($comment->comment_author) . ' 给您的回复如下:
'
. nl2br($comment->comment_content) . '


您可以点击


欢迎再次光临


(此邮件由系统自动发出,请勿回复。)


';
$message = convert_smilies($message);
$from = "From: "" . get_option('blogname') . "" ";
$headers = "$fromnContent-Type: text/html; charset=" . get_option('blog_charset') . "n";
wp_mail( $to, $subject, $message, $headers );
}
}
add_action('comment_post', 'comment_mail_notify');

如果系统不支持mail函数我们需要要安装一个SMTP的插件


下载好Configure SMTP插件、通过SVN上传到SAE博客上

登陆后台启用插件并开始配置、请仔细看下面的配置选项。

Send e-mail via GMail? 不用勾选

SMTP host:smtp.163.com,俺使用的伟大的163邮箱(推荐使用国内的邮箱,否则有可能收不到邮件)

SMTP port:25,一般SMTP服务器都是使用的这个端口

Secure connection prefix:留白、不用选

Use SMTPAuth? 必选

SMTP username:你的用户名,比如安的是[email protected] SMTP password:邮箱密码,123456789

Wordwrap length:留白

Enable debugging? 启用调试模式,不选

Sender e-mail:发送者邮箱,还写上面的[email protected]

Sender name:发送者的姓名,吧你希望显示的名称填上即可
保存之后我们自己测试一把去
点击下面的 Send Test e-mail 按钮吧。
到此你的SAE上的wordpress博客在有评论的时候都会发送邮件给你哦,然后如果你在回复其他人的评论的时候也会有邮件过去。当然如果新用户注册的时候也会有邮件通知的。

热门栏目