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

最新下载

热门教程

WordPress增加评论自动邮件通知博主的功能

时间:2014-01-10 编辑:简简单单 来源:一聚教程网

方法一,windows,linux主机

根据自己的需要,选择一种自己需要的代码,添加在主题的 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 = 'no-reply@' . 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 = '
   


     

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


     

您曾在《' . get_the_title($comment->comment_post_ID) . '》的留言:
'
       . trim(get_comment($parent_id)->comment_content) . '


     

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


     

您可以点击 查看回复完整?热?lt;/p>
     

欢迎再度光临 ' . get_option('blogname') . '


     

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


   
';
      $from = "From: "" . get_option('blogname') . "" <$wp_email>";
      $headers = "$from Content-Type: text/html; charset=" . get_option('blog_charset') . " ";
      wp_mail( $to, $subject, $message, $headers );
  }
}
add_action('comment_post', 'comment_mail_notify');
// -- END ----------------------------------------

方法二,针对在SAE上的WordPress增加评论自动邮件通知功能


如果你是自己购买的虚拟主机/VPS之类的话就直接安装一个SMTP的邮件插件就可以了、但是如果你和我一样吧博客放在SAE上的话、就需要做一些修改才行了。

首先;我们需要修改functions.php文件
你需要把我下面的PHP代码复制黏贴到你主题的functions.php文件中的之间

你可以通过SAE的 Editor也可以在本地修改好代码之后用SVN上传、推荐用SVN吧

 代码如下 复制代码

/* comment_mail_notify by http://www.111com.net (所有回复都发邮件) */
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 发出点, no-reply 可改为可用的 e-mail.
    $to = trim(get_comment($parent_id)->comment_author_email);
    $subject = '您在 [' . get_option("blogname") . '] 的留言有了回复';
    $message = '
   

     

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


     

您曾在《' . get_the_title($comment->comment_post_ID) . '》的留言:
'
       . trim(get_comment($parent_id)->comment_content) . '


     

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


     

您可以点击 查看回复完整?热?lt;/a>


     

欢迎再度光临 ' . get_option('blogname') . '


     

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


   
';
    $from = "From: "" . get_option('blogname') . "" <$wp_email>";
    $headers = "$from Content-Type: text/html; charset=" . get_option('blog_charset') . " ";
    wp_mail( $to, $subject, $message, $headers );
    //echo 'mail to ', $to, '
' , $subject, $message;
  }
}
add_action('comment_post', 'comment_mail_notify');

// -- END ----------------------------------------接着;我们需要安装一个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:你的用户名,比如安的是hiadmin_email@163.com SMTP password:邮箱密码,123456789

Wordwrap length:留白

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

Sender e-mail:发送者邮箱,还写上面的hiadmin_email@163.com

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

 

热门栏目