【问题标题】:How to set DSN (Delivery Status Notification) for PHPMailer?如何为 PHPMailer 设置 DSN(交付状态通知)?
【发布时间】:2012-05-10 05:16:35
【问题描述】:

我正在尝试了解如何在使用 PHPMailer 时设置 DSN。我知道在 SMTP 协议级别,DSN 是在 RCPT TO 之后指定的,例如RCPT TO:NOTIFY=SUCCESS,FAILURE ORCPT=rfc822;recipientemail@gmail.com

此外,如果可能的话,我希望将 DSN 定向到发件人地址以外的地址。感谢任何指点,谢谢。

【问题讨论】:

    标签: php email smtp phpmailer


    【解决方案1】:

    发现PHPMailer不支持DSN,只好自己修改class.smtp.php。

    原代码:

    fputs($this->smtp_conn,"RCPT TO:<" . $to . ">" . $this->CRLF);
    

    改为:

     fputs($this->smtp_conn,"RCPT TO:<" . $to . "> NOTIFY=SUCCESS,FAILURE ORCPT=rfc822;" . $to ."" . $this->CRLF);
    

    至于将DSN定向到发件人地址以外,可以通过定义实现:

     $mail->Sender = "bounced@email.com";
    

    【讨论】:

    • 这是真的,但你不能只是添加它并期望它工作 - 服务器需要支持它,如果支持它,它将在 EHLO 响应中列为 DSN ,根据RFC3461
    【解决方案2】:

    我只是测试,它对我有用,修改class.smtp.php

    原始代码:

    public function recipient($toaddr)
    {
        return $this->sendCommand(
            'RCPT TO',
            'RCPT TO:<' . $toaddr . '>',
            array(250, 251)
        );
    }
    

    例如,改为:

    public function recipient($toaddr)
    {
        return $this->sendCommand(
            'RCPT TO',
            'RCPT TO:<' . $toaddr . '> NOTIFY=SUCCESS,FAILURE ORCPT=rfc822;',
            array(250, 251)
        );
    }
    

    【讨论】:

      【解决方案3】:

      在我可以看到的 smtp 文件中没有 fputs($this->smtp_conn,"RCPT TO: 等行的最新版本的 phpmailer 中如何做到这一点?

      最接近它,我可以看到是唯一提到 RCPT TO 的地方。

      public function recipient($toaddr)
      {
          return $this->sendCommand(
              'RCPT TO',
              'RCPT TO:<' . $toaddr . '>',
              array(250, 251)
          );
      }
      

      【讨论】:

        【解决方案4】:

        我发现了在 PHPMAiler 上设置 DSN 的官方命令:

        $mail->dsn = '成功、失败、延迟';

        这三个命令可以按时使用,也可以单独使用。

        例如:

        $mail = new PHPMailer(true);
        $mail->dsn = 'SUCCESS';
        

        服务器默认启用 SUCCESS 和 FAILURE 命令,但必须 SUCCESS 才能启用返回“Deliver Status Notification”(Notificaçãode Status de Entrega)。

        注意:验证“PHPMailer.php”的第343行以获得更多说明。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2016-02-08
          • 1970-01-01
          • 2018-02-11
          • 2016-07-11
          • 2013-01-13
          • 2012-07-31
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多