Search code examples
phpmailer

PHPMailer bounce email address shows in sender mailbox


I am using a PHP script to send emails using PHPMailer (on an ovh web server).

  • With the following script :
      $mail->isMail();
      ......
      $mail->addReplyTo('postmaster@mydomain.fr', 'Site');
      $mail->SetFrom('postmaster@mydomain.fr', 'Site');

Emails get delivered to my gmail account BUT not to other addresses (e.g. my Business email).

  • With the following script :
      $mail->isMail();
      ......
      $mail->addReplyTo('postmaster@mydomain.fr', 'Site');
      $mail->Sender = 'postmaster@mydomain.fr';

Emails get delivered to other addresses (e.g. my Business email) BUT not to gmail.

Also the sender appears as bounce-id=D004=U58180. …… .net

which is not so friendly.

Is there a way to solve those issues ?


Solution

  • Using setFrom by itself will result in Sender being set to the same value as your from address (look at the code in the setFrom method). So in your second example you're setting the envelope sender, but not the from address, which is likely not what you want.

    You may find it easier to use SMTP to localhost instead of isMail(); just changing that method to isSMTP() should be enough to do that. That way you can set SMTPDebug = 2 and see exactly what your local mail server is saying.

    Separately, you don't need to set a reply-to address if it's the same as your from address – PHPMailer will simply ignore it if you try to set them to the same value anyway.