Php – Why postfix doesn’t follow From header from PHP mail();

debianemailPHPpostfix

I have installed postfix with no config option.

I am trying to send email with php mail(); it works but it sends email with the default email of my dedicated server.

Are there anyway to tell postfix to follow the header set by mail function?

Thanks

Code

$from='no-reply@mywebsite.com';
$fromname='my Website';
mail($mailto,$subject,$text,'From: ' . $fromname . ' <'.$from.'>');

Best Answer

Try using the -f and -r additional parameters to override the from header and return path respectively.

mail(
    $mailto,
    $subject,
    $text,
    "From: " . $fromname . " <".$from.">",
    "-f $from -r mybounceemail@example.com");

From the postfix sendmail man page:

   -f sender
     Set the envelope sender address. This is the address where delivery problems are sent to.  With  Postfix  versions  before  2.1,  the
     Errors-To: message header overrides the error return address.


   -r sender
     Set the envelope sender address. This is the address where delivery problems are sent to.  With  Postfix  versions  before  2.1,  the
     Errors-To: message header overrides the error return address.
Related Topic