How to set DSN (delivery status notification) for PHPMailer?

I am trying to figure out how to install DSN when using PHPMailer. I know at the SMTP protocol level, DSN is indicated after RCPT TO, for example. RCPT TO: NOTIFY = SUCCESS, FAULT ORCPT = rfc822; recipientemail@gmail.com

In addition, I would like to forward the DSN to a destination other than the sender address, if possible. Appreciate any pointers, thanks.

+3
source share
3 answers

I found that PHPMailer does not support DSN, so I had to change the class.smtp.php class itself.

Original code:

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

Change to:

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

As for directing the DSN to a destination other than the sender address, this can be achieved by determining:

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

, , 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)
    );
}
+1

How to do this in the latest version of phpmailer, where there are no fputs ($ this-> smtp_conn, "RCPT TO: <". $ To. "> Etc. line in the smtp file anywhere I can see?

Closer to this, what I see is the only place where RCPT TO is mentioned.

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

All Articles