欢迎您光临爱尚资源网,本站秉承服务宗旨 履行“站长”责任,销售只是起点 服务永无止境!
  • 正文概述
  • 更新记录
  • 很多时候,人们都希望在自己的评论被管理员回复后会收到通知。该函数的作用就是回复后自动邮件通知评论者。

    把下面的代码加到wordpress的主题函数里面,然后修改下邮件帐号密码。

    该函数是针对SAE平台的wordpress,非SAE平台不能使用,有需要的话留言我也会写出相应方法。

      //邮件回复
      function comment_mail_notify($comment_id) {
      define('MAIL_SMTP', 'smtp.exmail.qq.com'); //smtp服务器
      define('MAIL_PORT', 25); //smtp端口
      define('MAIL_SENDEMAIL', '123456789@qq.com'); //发送邮件帐号
      define('MAIL_PASSWORD', '123456'); //发送邮件密码
      $admin_notify = '1';
      $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 : '';
      global $wpdb;
      if ($wpdb->query("Describe {$wpdb->comments} comment_mail_notify") == '')
      $wpdb->query("ALTER TABLE {$wpdb->comments} ADD COLUMN comment_mail_notify TINYINT NOT NULL DEFAULT 0;");
      if (($comment_author_email != $admin_email && isset($_POST['comment_mail_notify'])) || ($comment_author_email == $admin_email && $admin_notify == '1'))
      $wpdb->query("UPDATE {$wpdb->comments} SET comment_mail_notify='1' WHERE comment_ID='$comment_id'");
      $notify = $parent_id ? '1' : '0';
      $spam_confirmed = $comment->comment_approved;
      if ($parent_id != '' && $spam_confirmed != 'spam' && $notify == '1') {
      $wp_email = 'no-reply@' . preg_replace('#^www\.#', '', strtolower($_SERVER['SERVER_NAME']));
      $to = trim(get_comment($parent_id)->comment_author_email);
      $subject = '你在' . get_option("blogname") . '回复被关注啦~';
      $message = '
      <div style="width: 502px; height: auto; margin-bottom: 50px; margin-left: auto; margin-right: auto; font-size: 13px; line-height: 14px;">
      <div style="width: 502px; margin-top: 10px;">
      <div style="font-size: 16px; color: #373737; text-align: center;">'.get_bloginfo("name").'</div>
      <div style="font-size: 15px; color: #f0f7eb; padding: 9px; margin-top: 20px; overflow: hidden; background: #299982; padding-left: 30px; padding-right: 40px;">你在 '. get_the_title($comment-&gt;comment_post_ID) .' 的评论有了回复:</div>
      </div>
      <div style="width: 420px; margin-top: 30px; padding: 0 40px 20px; border-left: 1px dashed #299982; border-right: 1px dashed #299982; color: rgba(0,0,0,0.7); background: #f9f9f9; overflow: hidden;">
      <div class="one origin" style="border: 1px solid #EEE; overflow: auto; padding: 10px; margin: 1em 0;"><span style="color: #299982;">'. trim(get_comment($parent_id)-&gt;comment_author) .'</span>:'. trim(get_comment($parent_id)-&gt;comment_content) .'</div>
      <div class="one reply" style="border: 1px solid #EEE; overflow: auto; padding: 10px; margin: 1em 0 1em 60px;"><span style="color: #299982;">'. trim($comment-&gt;comment_author) .'</span>:'. trim($comment-&gt;comment_content) .'</div>
      <p style="margin-bottom: 10px;">点击<a href="' . htmlspecialchars(get_comment_link($parent_id)) . ' style=">查看完整内容</a></p>
      <p style="margin-bottom: 10px;">(此邮件由系统发出,无需回复.)</p>
      </div>
      </div>
      ';
      $from = "From: \"" . get_option('blogname') . "\" <$wp_email>";
      $headers = "$from\nContent-Type: text/html; charset=" . get_option('blog_charset') . "\n";
      $mail = new SaeMail(); //对象
      $mail->setOpt(array( 'from' => 'admin@xtwind.com', 'to' => trim($to),//接收信箱
      'smtp_host' => MAIL_SMTP , //host
      'smtp_port' => MAIL_PORT, //port
      'smtp_username' => MAIL_SENDEMAIL,
      'smtp_password' => MAIL_PASSWORD,
      'subject' => $subject,
      'content' => $message,
      'content_type' => 'HTML'
      // 'tls' => true,
      //'charset' => 'gbk' ) );
      $ret = $mail->send();
      }
      }
      add_action('comment_post', 'comment_mail_notify');
    1. 本站所有资源来源于用户上传和网络,如有侵权请邮件联系站长!
    2. 分享目的仅供大家学习和交流,请不要用于商业用途!
    3. 如果你也有好源码或者教程,可以到用户中心发布,分享有积分奖励和额外收入!
    4. 本站提供的源码、模板、插件等等其他资源,都不包含技术服务请大家谅解!
    5. 如有链接无法下载、失效或广告,请联系管理员处理!
    6. 本站资源售价只是赞助,收取费用仅维持本站的日常运营所需!
    7. 如遇到加密压缩包,默认解压密码为"dtmb.taobao.com",如遇到无法解压的请联系管理员!
    8. 因为资源和程序源码均为可复制品,所以不支持任何理由的退款兑现,请斟酌后支付下载
    声明如果标题没有注明"已测试"或者"测试可用"等字样的资源源码均未经过站长测试.特别注意没有标注的源码不保证任何可用性

    尚艺源码网 » WordPress实现回复文章评论后发送邮件通知的功能

    常见问题FAQ

    免费下载或者VIP会员专享资源能否直接商用?
    本站所有资源版权均属于原作者所有,这里所提供资源均只能用于参考学习用,请勿直接商用。若由于商用引起版权纠纷,一切责任均由使用者承担。更多说明请参考 VIP介绍。
    提示下载完但解压或打开不了?
    最常见的情况是下载不完整: 可对比下载完压缩包的与网盘上的容量,若小于网盘提示的容量则是这个原因。这是浏览器下载的bug,建议用百度网盘软件或迅雷下载。 若排除这种情况,可在对应资源底部留言,或 联络我们.。
    你们有qq群吗怎么加入?
    当然有的,如果你是帝国cms、易优cms、和pbootcms系统的爱好者你可以加入我们的QQ千人交流群160457583

    发表评论

    开通VIP 享更多特权,建议使用 QQ 登录