1

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.'>');
8
  • what version of sendmail & php? What is sendmail_path configured as in php.ini?
    – jamespo
    Apr 10, 2011 at 21:20
  • it's postfix not sendemail. and php is 5.3.x
    – dynamic
    Apr 10, 2011 at 21:26
  • 1
    sorry which version of postfix, and what is the path configured (with any arguments?)
    – jamespo
    Apr 10, 2011 at 21:27
  • it's /usr/sbin/sendmail -t -i O_O but i don't have sendmail lol. Thanks for any help
    – dynamic
    Apr 10, 2011 at 21:33
  • 1
    Can you post how you're calling the mail() method? Apr 10, 2011 at 22:17

2 Answers 2

4

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.
2
  • thanks I will try. But Why should i set the -r?
    – dynamic
    Apr 10, 2011 at 22:39
  • 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 Apr 10, 2011 at 22:45
1

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 do_not_reply@your.com
2
  • 3
    thanks for the add.. but is there a reason on why the header arg doenst' work?
    – dynamic
    Apr 15, 2011 at 18:44
  • You need to also add the -i option to this or a single line with a . in int will flag end of input.
    – Geoffrey
    Nov 9, 2018 at 7:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.