如何为PHPMailer设置DSN(传递状态通知)?

时间:2012-04-30 13:50:47

标签: php email smtp phpmailer

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

另外,如果可能的话,我想将DSN指向发件人地址以外的地址。感谢任何指点,谢谢。

3 个答案:

答案 0 :(得分:5)

我发现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";

答案 1 :(得分:1)

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

原始代码:

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

例如,更改为:

history: string[] = [];

constructor(private router: Router) {
    router.events
        .filter(event => event instanceof NavigationEnd)
        .subscribe(event => {
            this.history.push(event.url);
        });
}

onBack() {
    if (this.history.length > 1) {
        // pop current page
        this.history.pop();
        // pop previous page (later it will be added)
        this.history.pop();
        window.history.back();
    }
}

onHome() {
    window.location.replace(window.location.origin);
}

答案 2 :(得分:0)

如何在没有fput的最新版本的phpmailer中完成此操作($ this-&gt; smtp_conn,&#34; RCPT TO:&lt;&#34;。$ to。&#34;&gt;在我能看到的任何地方的smtp文件中的哪一行?

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

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