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

We have a Linux server with a single site set up on it (site1.com), down the road we may set up additional sites.

When we send an email through php it comes from www-data@site1.com
We would like to change it to contactus@site1.com, but also make it so that when we add site2.com down the road, we can have the default email set to admin@site2.com for instance.

I tried setting it in .htaccess, but that didn't seem to work. maybe I did it wrong.

php_value force_sender contactus@site1.com

Linux noob, so what's the best way to do this?

share|improve this question
php.net/manual/en/function.mail.php last parmater to function mail: -f set envelope sender. –  RJS Oct 5 '12 at 13:54
Yeah, I've used -f, I'm just hoping there is a way to set a default value that's different for each site. Otherwise we'll have to set the default to something that isn't site specific. –  AndyD273 Oct 5 '12 at 14:38

1 Answer 1

up vote 1 down vote accepted

the force_sender option probably only works when sending mails over SMTP, not via the sendmail binary (default).

you can try to pass the envelope sender via an additinal -f parameter in mail():

mail('recipient@example.com',$subject,$body,$yourheaders,'-f sender@example.net');

not all installations allow -f overrides though. if it doesn't work, use one of the many helper classes like phpmailer which send via smtp and allow you to specify the envelope sender.

share|improve this answer
Yeah, I know about that... I was just hoping to have a way to make a different default for each domain, and then use the -f to customize it as needed. –  AndyD273 Oct 5 '12 at 14:31
maybe you could try overriding the sendmail_path per domain like explained in the top answer here: serverfault.com/questions/165499/… - haven't tried myself though –  Gryphius Oct 5 '12 at 15:05

Your Answer


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.