3

I'm trying to find out how to set DSN when using PHPMailer. I know at the SMTP Protocol level, the DSN is specified after RCPT TO, e.g. RCPT TO: NOTIFY=SUCCESS,FAILURE ORCPT=rfc822;recipientemail@gmail.com

Also, I will like to direct the DSN to other than the sender address if that is possible. Appreciate any pointers, thanks.

Joshua
  • 1,709
  • 2
  • 24
  • 38

4 Answers4

5

I discovered that PHPMailer doesn't support DSN, so I had to amend class.smtp.php 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 DSN to other than sender address, this can be achieved by defining:

 $mail->Sender = "bounced@email.com";
Joshua
  • 1,709
  • 2
  • 24
  • 38
  • 1
    This is true, but you can't just add that and expect it to work - the server needs to support it, and if it does, it will be listed in the EHLO response as `DSN`, as per [RFC3461](http://tools.ietf.org/html/rfc3461). – Synchro Jul 24 '14 at 10:19
1

I just test,it work for me, modify class.smtp.php

Original Code:

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

for example, Change to:

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

How would this be done in the latest version of phpmailer where there is no fputs($this->smtp_conn,"RCPT TO:<" . $to . "> etc. line within the smtp file anywhere that I can see?

Closest to it, that I can see is the only place RCPT TO is mentioned.

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

I've discovered the official command to set the DSN on PHPMAiler:

$mail->dsn = 'SUCCESS,FAILURE,DELAY';

Is possible to use the three commands on time, or isolated.

Ex:

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

The commands SUCCESS and FAILURE is enabled by default on server, but SUCCESS is a neccessary to enable the return of "Deliver Status Notification" (Notificação de Status de Entrega).

Attention: Verify the line 343 of "PHPMailer.php" for more instructions.