Apache – Virtual Hosts and Default Sender for Sendmail

apache-2.2PHPsendmailunixvirtualhost

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?

Best Answer

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"
    </Directory>

</VirtualHost>

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.