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.

So here's my issue...I have two sites hosted on one machine using apache's virtual hosts. I want to send emails from the two different sites (domain.com and domain2.com) using the appropriate email addresses. I currently have this value in php.ini:

sendmail_path = /usr/sbin/sendmail -t -i -fuser@domain.com

But when I try sending an email from a script on domain2.com it obviously is delivered with a From: user@domain.com header. Apache doesn't allow you to set a rule like this from within the <VirtualHost> directive:

php_admin_value sendmail_path "/usr/sbin/sendmail -t -i -fuser@domain2.com"

So what's the best way to accomplish this? I've tried setting php_admin_value mail.force_extra_parameters "-fuser@domain2.com" from within the domain2.com's <VirtualHost> directive but all emails are still coming from domain.com. Any ideas?

share|improve this question
Plase see: stackoverflow.com/questions/179014/… –  jeffatrackaid Dec 7 '11 at 17:12
I saw that, but editing every mail() call wasn't a viable option for me –  Jeff Dec 8 '11 at 0:55

2 Answers 2

up vote 2 down vote accepted

Although you're not allowed to set the sendmail_path from within the <VirtualHost> directive, you can set it within the <Directory> directive. So I simply have something that looks like this:

<VirtualHost *:80>
    Standard stuff goes here

    <Directory /dir/to/your/web/root>
        php_admin_value sendmail_path "/usr/sbin/sendmail -t -i -fuser@domain2.com"


I'm not sure if it's the most proper or elegant way to accomplish this, but it definitely worked. Sorry it took so long to respond, I don't go on SF that frequently and forgot about this question.

share|improve this answer
Jeff, I couldn't up your response but THANK YOU! I've been fighting this for three days now with no success and your response is the first one that actually gets my e-mails to send! Elegant or not, a send is better than not! –  Beshoy Girgis Sep 5 '13 at 5:36

You have to remove the -fuser@domain.com from your php.ini. And then modify the mail function for each script that sends mail for each host appropriately. That way you can pass the correct -f argument for each virtual host.

share|improve this answer
Sorry, I should have added that in my OP. I did remove the -fuser@domain.com from the php.ini file prior to adding the mail.force_extra_parameters to the vhost's conf file. That still wasn't working. I found a way that worked for me that I'll be posting later tonight –  Jeff Dec 8 '11 at 0:59
Please post it for another user seems to be having the same problem –  adamo Dec 14 '11 at 7:10
Yes, this info would be greatly appreciated! :) –  Minty Dec 14 '11 at 20:15
Whoops sorry for the delayed answer. I completely forgot about this question because I don't come over to SF too frequently –  Jeff Feb 3 '12 at 3:28

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.