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]
Author by
dynamic
Updated on September 18, 2022Comments
-
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 about 13 yearsit's postfix not sendemail. and php is 5.3.x
-
Dasch33 about 13 yearssorry which version of postfix, and what is the path configured (with any arguments?)
-
dynamic about 13 yearsit's
/usr/sbin/sendmail -t -i
O_O but i don't have sendmail lol. Thanks for any help -
chrishiestand about 13 yearsCan you post how you're calling the mail() method?
-
Dasch33 about 13 yearsIs safe mode enabled in php.ini?
-
dynamic about 13 yearsnope it's off...
-
-
dynamic about 13 yearsthanks I will try. But Why should i set the -r?
-
chrishiestand about 13 yearsIt'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 about 13 yearsthanks for the add.. but is there a reason on why the header arg doenst' work?
-
Geoffrey over 5 yearsYou need to also add the
-i
option to this or a single line with a.
in int will flag end of input.