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 -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?

Jeff
  • 205
  • 3
  • 12

3 Answers3

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 -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.

Jeff
  • 205
  • 3
  • 12
  • 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 05 '13 at 05:36
0

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.

adamo
  • 6,867
  • 3
  • 29
  • 58
  • 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 08 '11 at 00:59
  • Please post it for another user seems to be having [the same problem](http://serverfault.com/questions/340734/setting-the-from-address-apache-php-sendmail) – adamo Dec 14 '11 at 07: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 03 '12 at 03: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.