Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.'>');
share|improve this question
    
what version of sendmail & php? What is sendmail_path configured as in php.ini? –  jamespo Apr 10 '11 at 21:20
    
it's postfix not sendemail. and php is 5.3.x –  dynamic Apr 10 '11 at 21:26
1  
sorry which version of postfix, and what is the path configured (with any arguments?) –  jamespo Apr 10 '11 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 '11 at 21:33
1  
Can you post how you're calling the mail() method? –  chrishiestand Apr 10 '11 at 22:17

2 Answers 2

up vote 3 down vote accepted

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.
share|improve this answer
    
thanks I will try. But Why should i set the -r? –  dynamic Apr 10 '11 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 –  chrishiestand Apr 10 '11 at 22:45

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
share|improve this answer
1  
thanks for the add.. but is there a reason on why the header arg doenst' work? –  dynamic Apr 15 '11 at 18:44

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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