1

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 [email protected]

But when I try sending an email from a script on domain2.com it obviously is delivered with a From: [email protected] 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 [email protected]"

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

2

3 Answers 3

7

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 [email protected]"
    </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.

1
  • 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! Sep 5, 2013 at 5:36
0

You have to remove the [email protected] 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.

4
  • Sorry, I should have added that in my OP. I did remove the [email protected] 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, 2011 at 0:59
  • Please post it for another user seems to be having the same problem
    – adamo
    Dec 14, 2011 at 7:10
  • Yes, this info would be greatly appreciated! :)
    – Minty
    Dec 14, 2011 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, 2012 at 3:28
0

I've been facing problem when i tryed to modify my sendmail_path using php_value or ini_set/ini_get (even with safe_mode off! i don't really know why - PHP 5.3.3). However i re-read the php mail() function, and it's the solution was on the function.

bool mail ( string $to , string $subject , string $message [, string $additional_headers [, string $additional_parameters ]] )

So last parameter allow additional parameters. I changed my php mail code from mail($to,$subject,$message,implode("\r\n", $headerFields), "-f".$from);

I think that's Jeff you'll find this smarter.

Hope this help.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .