Lan Tian @ Blog

基于 Mailgun 的 Typecho 评论邮件提醒插件

本文写于 772 天前, 随着软件更新、外部链接失效等原因,这些内容可能已经不再适用。 如果你发现这些问题,欢迎在评论区指出。

很多时候,在 WordPress、Typecho 等自建评论系统的网站中回复,只能靠自己不断访问来确定自己的评论有没有被别人回复。然而,对于大多数人来说这样做是非常麻烦的。

博主解决问题的常用方法,就是安装邮件提醒插件。当一名评论者的评论被回复,就会有邮件提醒评论者。

Typecho 上使用最广泛的插件是 CommentToMail,最早由 DEFE 开发,后来由 Byends Upd 接手。该插件通过常用的 PHP Mail,SendMail 或者 SMTP 来发送邮件。

但是,比起以前的注册一个邮箱来发提醒邮件,现在博主们也开始使用 Mailgun 之类的邮件平台。这类邮件平台提供 API 发信功能,不需要再进行复杂的 SMTP 发信设置,也不需要繁杂的处理代码。我就对这个插件进行修改,让它通过 Mailgun API 而不是 SMTP 发送邮件。

GitHub 项目地址:https://github.com/xddxdd/typecho-commentgun

版权所有 2019 Lan Tian @ Blog

本文链接 https://lantian.pub/article/modify-website/mailgun-typecho-comment-email-notification.lantian

CC BY-NC-SA 4.0 协议授权,转载请署名,禁止商业用途,请勿曲解原义

Lan Tian @ Blog 提醒您:

文章千万字,署名第一字。转载不规范,作者两行泪。

 

« 上一篇文章:
将网站迁移到 Docker
  1. 王忘杰

    王忘杰


    Warning: unpack(): Type V: not enough input, need 4, have 0 in /srv/www/lantian.pub/usr/themes/lantian/vendor/itbdw/ip-database/src/IpLocation.php on line 158

    Warning: unpack(): Type V: not enough input, need 4, have 0 in /srv/www/lantian.pub/usr/themes/lantian/vendor/itbdw/ip-database/src/IpLocation.php on line 158

    Warning: unpack(): Type V: not enough input, need 4, have 1 in /srv/www/lantian.pub/usr/themes/lantian/vendor/itbdw/ip-database/src/IpLocation.php on line 473

    Warning: unpack(): Type V: not enough input, need 4, have 0 in /srv/www/lantian.pub/usr/themes/lantian/vendor/itbdw/ip-database/src/IpLocation.php on line 158

    Warning: unpack(): Type V: not enough input, need 4, have 1 in /srv/www/lantian.pub/usr/themes/lantian/vendor/itbdw/ip-database/src/IpLocation.php on line 473

    Warning: unpack(): Type V: not enough input, need 4, have 0 in /srv/www/lantian.pub/usr/themes/lantian/vendor/itbdw/ip-database/src/IpLocation.php on line 158
      
    2017-06-09 23:08:56 沙发 回复 2017-06-09 23:08

    测试发现,游客评论后能发出邮件。但是回复游客的邮件却发不出来??

    1. Lan Tian

      Lan Tian

        
      2017-06-09 23:59:55 回复 2017-06-09 23:59

      代码里多打了一个空格……现在已经修复,麻烦再测试一下,谢谢

  2. 王忘杰

    王忘杰


    Warning: unpack(): Type V: not enough input, need 4, have 1 in /srv/www/lantian.pub/usr/themes/lantian/vendor/itbdw/ip-database/src/IpLocation.php on line 473

    Warning: unpack(): Type V: not enough input, need 4, have 0 in /srv/www/lantian.pub/usr/themes/lantian/vendor/itbdw/ip-database/src/IpLocation.php on line 158

    Warning: unpack(): Type V: not enough input, need 4, have 1 in /srv/www/lantian.pub/usr/themes/lantian/vendor/itbdw/ip-database/src/IpLocation.php on line 473

    Warning: unpack(): Type V: not enough input, need 4, have 0 in /srv/www/lantian.pub/usr/themes/lantian/vendor/itbdw/ip-database/src/IpLocation.php on line 158
      
    2017-06-09 23:14:44 板凳 回复 2017-06-09 23:14

    今天签到啦!时间:下午11:02:05

  3. Lan Tian

    Lan Tian

      
    2017-06-10 00:04:31 地毯 回复 2017-06-10 00:04

    测试评论

    1. 王忘杰

      王忘杰


      Warning: unpack(): Type V: not enough input, need 4, have 1 in /srv/www/lantian.pub/usr/themes/lantian/vendor/itbdw/ip-database/src/IpLocation.php on line 473

      Warning: unpack(): Type V: not enough input, need 4, have 0 in /srv/www/lantian.pub/usr/themes/lantian/vendor/itbdw/ip-database/src/IpLocation.php on line 158

      Warning: unpack(): Type V: not enough input, need 4, have 1 in /srv/www/lantian.pub/usr/themes/lantian/vendor/itbdw/ip-database/src/IpLocation.php on line 473

      Warning: unpack(): Type V: not enough input, need 4, have 0 in /srv/www/lantian.pub/usr/themes/lantian/vendor/itbdw/ip-database/src/IpLocation.php on line 158
        
      2017-06-10 00:19:39 回复 2017-06-10 00:19

      博主回复游客无效 Outgoing (30d)数字都没有变

      1. Lan Tian

        Lan Tian

          
        2017-06-10 00:39:38 回复 2017-06-10 00:39

        我在下面测试了一下,是可以正常回复游客的,包括你的评论我也能正常回复,只不过mailgun发QQ邮箱经常发不过去。
        你可以进mailgun的log面板看一下有没有邮件记录。
        楼中楼没回复按钮是我只开了两层评论,现在开到了五层
        点发表卡住是刚刚改javascript改错了

        1. 王忘杰

          王忘杰


          Warning: unpack(): Type V: not enough input, need 4, have 1 in /srv/www/lantian.pub/usr/themes/lantian/vendor/itbdw/ip-database/src/IpLocation.php on line 473

          Warning: unpack(): Type V: not enough input, need 4, have 0 in /srv/www/lantian.pub/usr/themes/lantian/vendor/itbdw/ip-database/src/IpLocation.php on line 158

          Warning: unpack(): Type V: not enough input, need 4, have 1 in /srv/www/lantian.pub/usr/themes/lantian/vendor/itbdw/ip-database/src/IpLocation.php on line 473

          Warning: unpack(): Type V: not enough input, need 4, have 0 in /srv/www/lantian.pub/usr/themes/lantian/vendor/itbdw/ip-database/src/IpLocation.php on line 158
            
          2017-06-10 01:07:47 回复 2017-06-10 01:07

          https://9sb.org/49 哦了 ,大佬能否把smtp插件也修修?https://9sb.org/45

          1. Lan Tian

            Lan Tian


            Warning: unpack(): Type V: not enough input, need 4, have 1 in /srv/www/lantian.pub/usr/themes/lantian/vendor/itbdw/ip-database/src/IpLocation.php on line 473

            Warning: unpack(): Type V: not enough input, need 4, have 0 in /srv/www/lantian.pub/usr/themes/lantian/vendor/itbdw/ip-database/src/IpLocation.php on line 158

            Warning: unpack(): Type V: not enough input, need 4, have 1 in /srv/www/lantian.pub/usr/themes/lantian/vendor/itbdw/ip-database/src/IpLocation.php on line 473

            Warning: unpack(): Type V: not enough input, need 4, have 0 in /srv/www/lantian.pub/usr/themes/lantian/vendor/itbdw/ip-database/src/IpLocation.php on line 158
              
            2017-06-10 01:18:09 2017-06-10 01:18

            如果你说的是CommentToMail插件的话,在Action.php的sendMail()函数中,在
            $mailer->SetFrom($this->_email->from, $this->_email->fromName);
            $mailer->AddReplyTo($this->_email->to, $this->_email->toName);
            $mailer->Subject = $this->_email->subject;
            $mailer->AltBody = $this->_email->altBody;
            $mailer->MsgHTML($this->_email->msgHtml);
            $mailer->AddAddress($this->_email->to, $this->_email->toName);
            这么一大段后插入:
            $mailer->SMTPOptions = array(
            'ssl' => array(
            'verify_peer' => false,
            'verify_peer_name' => false,
            'allow_self_signed' => true
            )
            );
            理论上就行了,我自己没测试过(因为没有能触发这个问题的邮箱)。

        2. 王忘杰

          王忘杰


          Warning: unpack(): Type V: not enough input, need 4, have 1 in /srv/www/lantian.pub/usr/themes/lantian/vendor/itbdw/ip-database/src/IpLocation.php on line 473

          Warning: unpack(): Type V: not enough input, need 4, have 0 in /srv/www/lantian.pub/usr/themes/lantian/vendor/itbdw/ip-database/src/IpLocation.php on line 158

          Warning: unpack(): Type V: not enough input, need 4, have 1 in /srv/www/lantian.pub/usr/themes/lantian/vendor/itbdw/ip-database/src/IpLocation.php on line 473

          Warning: unpack(): Type V: not enough input, need 4, have 0 in /srv/www/lantian.pub/usr/themes/lantian/vendor/itbdw/ip-database/src/IpLocation.php on line 158
            
          2017-06-10 20:25:03 回复 2017-06-10 20:25

          加上还是发不出去,QQ邮箱

          1. Lan Tian

            Lan Tian


            Warning: unpack(): Type V: not enough input, need 4, have 1 in /srv/www/lantian.pub/usr/themes/lantian/vendor/itbdw/ip-database/src/IpLocation.php on line 473

            Warning: unpack(): Type V: not enough input, need 4, have 0 in /srv/www/lantian.pub/usr/themes/lantian/vendor/itbdw/ip-database/src/IpLocation.php on line 158

            Warning: unpack(): Type V: not enough input, need 4, have 1 in /srv/www/lantian.pub/usr/themes/lantian/vendor/itbdw/ip-database/src/IpLocation.php on line 473

            Warning: unpack(): Type V: not enough input, need 4, have 0 in /srv/www/lantian.pub/usr/themes/lantian/vendor/itbdw/ip-database/src/IpLocation.php on line 158
              
            2017-06-10 20:29:33 2017-06-10 20:29

            CommentToMail 自带的 PHPMailer 太老了,所以加上参数没用。
            CommentToMail 的 lib 文件夹里有三个php文件,把它们用 https://github.com/PHPMailer/PHPMailer 上的对应的三个php替换掉应该就可以

        3. 王忘杰

          王忘杰


          Warning: unpack(): Type V: not enough input, need 4, have 1 in /srv/www/lantian.pub/usr/themes/lantian/vendor/itbdw/ip-database/src/IpLocation.php on line 473

          Warning: unpack(): Type V: not enough input, need 4, have 0 in /srv/www/lantian.pub/usr/themes/lantian/vendor/itbdw/ip-database/src/IpLocation.php on line 158

          Warning: unpack(): Type V: not enough input, need 4, have 1 in /srv/www/lantian.pub/usr/themes/lantian/vendor/itbdw/ip-database/src/IpLocation.php on line 473

          Warning: unpack(): Type V: not enough input, need 4, have 0 in /srv/www/lantian.pub/usr/themes/lantian/vendor/itbdw/ip-database/src/IpLocation.php on line 158
            
          2017-06-10 21:03:47 回复 2017-06-10 21:03

          替换后插件报错

          1. Lan Tian

            Lan Tian


            Warning: unpack(): Type V: not enough input, need 4, have 1 in /srv/www/lantian.pub/usr/themes/lantian/vendor/itbdw/ip-database/src/IpLocation.php on line 473

            Warning: unpack(): Type V: not enough input, need 4, have 0 in /srv/www/lantian.pub/usr/themes/lantian/vendor/itbdw/ip-database/src/IpLocation.php on line 158

            Warning: unpack(): Type V: not enough input, need 4, have 1 in /srv/www/lantian.pub/usr/themes/lantian/vendor/itbdw/ip-database/src/IpLocation.php on line 473

            Warning: unpack(): Type V: not enough input, need 4, have 0 in /srv/www/lantian.pub/usr/themes/lantian/vendor/itbdw/ip-database/src/IpLocation.php on line 158
              
            2017-06-10 22:07:48 2017-06-10 22:07

            在class.phpmailer.php开头加上:
            require_once 'class.smtp.php';
            require_once 'class.pop3.php';

        4. 王忘杰

          王忘杰


          Warning: unpack(): Type V: not enough input, need 4, have 1 in /srv/www/lantian.pub/usr/themes/lantian/vendor/itbdw/ip-database/src/IpLocation.php on line 473

          Warning: unpack(): Type V: not enough input, need 4, have 0 in /srv/www/lantian.pub/usr/themes/lantian/vendor/itbdw/ip-database/src/IpLocation.php on line 158

          Warning: unpack(): Type V: not enough input, need 4, have 1 in /srv/www/lantian.pub/usr/themes/lantian/vendor/itbdw/ip-database/src/IpLocation.php on line 473

          Warning: unpack(): Type V: not enough input, need 4, have 0 in /srv/www/lantian.pub/usr/themes/lantian/vendor/itbdw/ip-database/src/IpLocation.php on line 158
            
          2017-06-10 22:12:30 回复 2017-06-10 22:12

          OK了,谢谢大佬,QQ邮箱SMTP投递没有拒收不进垃圾桶,哈哈哈

        5. 王忘杰

          王忘杰


          Warning: unpack(): Type V: not enough input, need 4, have 1 in /srv/www/lantian.pub/usr/themes/lantian/vendor/itbdw/ip-database/src/IpLocation.php on line 473

          Warning: unpack(): Type V: not enough input, need 4, have 0 in /srv/www/lantian.pub/usr/themes/lantian/vendor/itbdw/ip-database/src/IpLocation.php on line 158

          Warning: unpack(): Type V: not enough input, need 4, have 1 in /srv/www/lantian.pub/usr/themes/lantian/vendor/itbdw/ip-database/src/IpLocation.php on line 473

          Warning: unpack(): Type V: not enough input, need 4, have 0 in /srv/www/lantian.pub/usr/themes/lantian/vendor/itbdw/ip-database/src/IpLocation.php on line 158
            
          2017-06-10 22:42:56 回复 2017-06-10 22:42

          不好。。评论和回复都不触发邮件了,只有点测试才能发出去,typecho1.1开发版

          1. Lan Tian

            Lan Tian


            Warning: unpack(): Type V: not enough input, need 4, have 1 in /srv/www/lantian.pub/usr/themes/lantian/vendor/itbdw/ip-database/src/IpLocation.php on line 473

            Warning: unpack(): Type V: not enough input, need 4, have 0 in /srv/www/lantian.pub/usr/themes/lantian/vendor/itbdw/ip-database/src/IpLocation.php on line 158

            Warning: unpack(): Type V: not enough input, need 4, have 1 in /srv/www/lantian.pub/usr/themes/lantian/vendor/itbdw/ip-database/src/IpLocation.php on line 473

            Warning: unpack(): Type V: not enough input, need 4, have 0 in /srv/www/lantian.pub/usr/themes/lantian/vendor/itbdw/ip-database/src/IpLocation.php on line 158
              
            2017-06-10 22:50:24 2017-06-10 22:50

            CommentToMail 用了异步触发,就是访客回复时,插件会自己去访问自己的一个页面,然后被访问的那个页面发信。
            异步触发中很多步骤都可能出问题,比如php无法访问到网站本身,或者执行到一半关闭连接时发送邮件的程序被关了。这些问题涉及到具体环境配置,所以我无法为你解决

    2. 王忘杰

      王忘杰


      Warning: unpack(): Type V: not enough input, need 4, have 1 in /srv/www/lantian.pub/usr/themes/lantian/vendor/itbdw/ip-database/src/IpLocation.php on line 473

      Warning: unpack(): Type V: not enough input, need 4, have 0 in /srv/www/lantian.pub/usr/themes/lantian/vendor/itbdw/ip-database/src/IpLocation.php on line 158

      Warning: unpack(): Type V: not enough input, need 4, have 1 in /srv/www/lantian.pub/usr/themes/lantian/vendor/itbdw/ip-database/src/IpLocation.php on line 473

      Warning: unpack(): Type V: not enough input, need 4, have 0 in /srv/www/lantian.pub/usr/themes/lantian/vendor/itbdw/ip-database/src/IpLocation.php on line 158
        
      2017-06-10 00:35:14 回复 2017-06-10 00:35

      我直接回复以前的评论不能发邮件,但是新建一个评论再回复就能发出了
      同时我发现,你的博客评论框 楼中楼 是没有回复按钮的。。

    3. 王忘杰

      王忘杰


      Warning: unpack(): Type V: not enough input, need 4, have 1 in /srv/www/lantian.pub/usr/themes/lantian/vendor/itbdw/ip-database/src/IpLocation.php on line 473

      Warning: unpack(): Type V: not enough input, need 4, have 0 in /srv/www/lantian.pub/usr/themes/lantian/vendor/itbdw/ip-database/src/IpLocation.php on line 158

      Warning: unpack(): Type V: not enough input, need 4, have 1 in /srv/www/lantian.pub/usr/themes/lantian/vendor/itbdw/ip-database/src/IpLocation.php on line 473

      Warning: unpack(): Type V: not enough input, need 4, have 0 in /srv/www/lantian.pub/usr/themes/lantian/vendor/itbdw/ip-database/src/IpLocation.php on line 158
        
      2017-06-10 00:35:52 回复 2017-06-10 00:35

      而且点完发表评论页面会卡住 刷新发现已经发出了

  4. 王忘杰

    王忘杰


    Warning: unpack(): Type V: not enough input, need 4, have 1 in /srv/www/lantian.pub/usr/themes/lantian/vendor/itbdw/ip-database/src/IpLocation.php on line 473

    Warning: unpack(): Type V: not enough input, need 4, have 0 in /srv/www/lantian.pub/usr/themes/lantian/vendor/itbdw/ip-database/src/IpLocation.php on line 158

    Warning: unpack(): Type V: not enough input, need 4, have 1 in /srv/www/lantian.pub/usr/themes/lantian/vendor/itbdw/ip-database/src/IpLocation.php on line 473

    Warning: unpack(): Type V: not enough input, need 4, have 0 in /srv/www/lantian.pub/usr/themes/lantian/vendor/itbdw/ip-database/src/IpLocation.php on line 158
      
    2017-06-11 00:39:23 4 楼 回复 2017-06-11 00:39

    非常感谢大佬,插件修好了
    2017 CommentToMail typecho版更新,支持php5.6/7,插件详解
    https://9sb.org/58

  5. 明月学习笔记Blog

    明月学习笔记Blog


    Warning: unpack(): Type V: not enough input, need 4, have 1 in /srv/www/lantian.pub/usr/themes/lantian/vendor/itbdw/ip-database/src/IpLocation.php on line 473

    Warning: unpack(): Type V: not enough input, need 4, have 0 in /srv/www/lantian.pub/usr/themes/lantian/vendor/itbdw/ip-database/src/IpLocation.php on line 158

    Warning: unpack(): Type V: not enough input, need 4, have 1 in /srv/www/lantian.pub/usr/themes/lantian/vendor/itbdw/ip-database/src/IpLocation.php on line 473

    Warning: unpack(): Type V: not enough input, need 4, have 0 in /srv/www/lantian.pub/usr/themes/lantian/vendor/itbdw/ip-database/src/IpLocation.php on line 158
      
    2017-06-11 19:17:51 5 楼 回复 2017-06-11 19:17

    QQ邮箱还是会经常的被屏蔽的,所以需要设定收件邮箱为非QQ邮箱就会好一些!

    1. Lan Tian

      Lan Tian


      Warning: unpack(): Type V: not enough input, need 4, have 1 in /srv/www/lantian.pub/usr/themes/lantian/vendor/itbdw/ip-database/src/IpLocation.php on line 473

      Warning: unpack(): Type V: not enough input, need 4, have 0 in /srv/www/lantian.pub/usr/themes/lantian/vendor/itbdw/ip-database/src/IpLocation.php on line 158

      Warning: unpack(): Type V: not enough input, need 4, have 1 in /srv/www/lantian.pub/usr/themes/lantian/vendor/itbdw/ip-database/src/IpLocation.php on line 473

      Warning: unpack(): Type V: not enough input, need 4, have 0 in /srv/www/lantian.pub/usr/themes/lantian/vendor/itbdw/ip-database/src/IpLocation.php on line 158
        
      2017-06-11 19:18:58 回复 2017-06-11 19:18

      访客用QQ邮箱有什么办法……难道屏蔽他们?

      1. 明月学习笔记Blog

        明月学习笔记Blog


        Warning: unpack(): Type V: not enough input, need 4, have 1 in /srv/www/lantian.pub/usr/themes/lantian/vendor/itbdw/ip-database/src/IpLocation.php on line 473

        Warning: unpack(): Type V: not enough input, need 4, have 0 in /srv/www/lantian.pub/usr/themes/lantian/vendor/itbdw/ip-database/src/IpLocation.php on line 158

        Warning: unpack(): Type V: not enough input, need 4, have 1 in /srv/www/lantian.pub/usr/themes/lantian/vendor/itbdw/ip-database/src/IpLocation.php on line 473

        Warning: unpack(): Type V: not enough input, need 4, have 0 in /srv/www/lantian.pub/usr/themes/lantian/vendor/itbdw/ip-database/src/IpLocation.php on line 158
          
        2017-06-11 23:57:52 回复 2017-06-11 23:57

        呵呵,我才发现其实QQ邮箱里可以申诉的!

  6. 逗妇乳

    逗妇乳


    Warning: unpack(): Type V: not enough input, need 4, have 1 in /srv/www/lantian.pub/usr/themes/lantian/vendor/itbdw/ip-database/src/IpLocation.php on line 473

    Warning: unpack(): Type V: not enough input, need 4, have 0 in /srv/www/lantian.pub/usr/themes/lantian/vendor/itbdw/ip-database/src/IpLocation.php on line 158

    Warning: unpack(): Type V: not enough input, need 4, have 1 in /srv/www/lantian.pub/usr/themes/lantian/vendor/itbdw/ip-database/src/IpLocation.php on line 473

    Warning: unpack(): Type V: not enough input, need 4, have 0 in /srv/www/lantian.pub/usr/themes/lantian/vendor/itbdw/ip-database/src/IpLocation.php on line 158
      
    2017-08-29 09:14:37 6 楼 回复 2017-08-29 09:14

    不兼容我的主题,配置好了以后评论没邮件。

    1. Lan Tian

      Lan Tian


      Warning: unpack(): Type V: not enough input, need 4, have 1 in /srv/www/lantian.pub/usr/themes/lantian/vendor/itbdw/ip-database/src/IpLocation.php on line 473

      Warning: unpack(): Type V: not enough input, need 4, have 0 in /srv/www/lantian.pub/usr/themes/lantian/vendor/itbdw/ip-database/src/IpLocation.php on line 158

      Warning: unpack(): Type V: not enough input, need 4, have 1 in /srv/www/lantian.pub/usr/themes/lantian/vendor/itbdw/ip-database/src/IpLocation.php on line 473

      Warning: unpack(): Type V: not enough input, need 4, have 0 in /srv/www/lantian.pub/usr/themes/lantian/vendor/itbdw/ip-database/src/IpLocation.php on line 158
        
      2017-09-07 15:47:21 回复 2017-09-07 15:47

      一般来说这个插件和主题是互不影响的,你去mailgun控制面板上看一下mailgun的发送日志,可能是被拒收了

昵称
邮箱
网站
 
Warning: unpack(): Type V: not enough input, need 4, have 1 in /srv/www/lantian.pub/usr/themes/lantian/vendor/itbdw/ip-database/src/IpLocation.php on line 473

Warning: unpack(): Type V: not enough input, need 4, have 0 in /srv/www/lantian.pub/usr/themes/lantian/vendor/itbdw/ip-database/src/IpLocation.php on line 158

Warning: unpack(): Type V: not enough input, need 4, have 1 in /srv/www/lantian.pub/usr/themes/lantian/vendor/itbdw/ip-database/src/IpLocation.php on line 473

Warning: unpack(): Type V: not enough input, need 4, have 0 in /srv/www/lantian.pub/usr/themes/lantian/vendor/itbdw/ip-database/src/IpLocation.php on line 158