Search code examples
phpemailsmtpphpmailer

How to set DSN (Delivery Status Notification) for PHPMailer?


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;[email protected]

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


Solution

  • 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 = "[email protected]";