Why postfix doesn't follow From header from PHP mail();

6,250

Solution 1

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

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.

Solution 2

If you have a million mail() and do not want to recode all your mail() functions... you can set in your php.ini the following... and it will universally set all you php mail() functions to use it.

sendmail_path = sendmail -t -f [email protected]
Share:
6,250
dynamic
Author by

dynamic

Updated on September 18, 2022

Comments

  • dynamic
    dynamic over 1 year

    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='[email protected]';
    $fromname='my Website';
    mail($mailto,$subject,$text,'From: ' . $fromname . ' <'.$from.'>');
    
    • dynamic
      dynamic about 13 years
      it's postfix not sendemail. and php is 5.3.x
    • Dasch33
      Dasch33 about 13 years
      sorry which version of postfix, and what is the path configured (with any arguments?)
    • dynamic
      dynamic about 13 years
      it's /usr/sbin/sendmail -t -i O_O but i don't have sendmail lol. Thanks for any help
    • chrishiestand
      chrishiestand about 13 years
      Can you post how you're calling the mail() method?
    • Dasch33
      Dasch33 about 13 years
      Is safe mode enabled in php.ini?
    • dynamic
      dynamic about 13 years
      nope it's off...
  • dynamic
    dynamic about 13 years
    thanks I will try. But Why should i set the -r?
  • chrishiestand
    chrishiestand about 13 years
    It's best practice to set the return-path as well, only if you want to handle bounced messages separately than the regular postfix config. By creatively setting the return path, you can even add intelligent bounce handling, see VERP: en.wikipedia.org/wiki/Variable_envelope_return_path
  • dynamic
    dynamic about 13 years
    thanks for the add.. but is there a reason on why the header arg doenst' work?
  • Geoffrey
    Geoffrey over 5 years
    You need to also add the -i option to this or a single line with a . in int will flag end of input.