postfix, php mail(), google apps, virtual hosts [SOLVED]
$ posconf -n
says:
inet_interfaces = loopback-only
mydestination = localhost.mydomainhere.com, localhost
mydomain = mydomainhere.com
myhostname = hostname.mydomainhere.com
mynetworks_style = host
myorigin = $mydomain
I have also set up apache & php, and I have name based virtual hosts (few sites). All domains have Google Apps on & MX's set up. Problem is that all mail that I send, no matter the domain, has
From: http@mydomainhere.com
I would like to set up postfix / php / apache to send mail with From: that states host from which it's sent.
So, if mail is sent from some php script on domain1.com i'd like it to show http@domain1.com, not http@mydomainhere.com.
Setting sendmailfrom didn't help (via iniset, or via .htaccess php_value). What am I missing in my configuration?
6 Replies
Otherwise, there is the PHP.ini option sendmail_from, but afaik that is for Windows only, I don't know if it is taken into consideration on Linux.
I'd rather try to set this up automagically than to edit all mailer scripts… And I believe there is a way to do it. I'm not tied to postfix - I'm open to any solution that would get this working.
mail.forceextraparameters = "-f
But you have to set that in php.ini, afaik you can't set it via .htaccess.
@kornrunner:
I would like to set up postfix / php / apache to send mail with From: that states host from which it's sent.
The default value for "myorigin" is $myhostname. If you drop the "myorigin = $mydomain" line from main.cf I think you will get the behavior you are looking for.
Removing myorigin from main.cf resulted in all mail to be sent from @myhostname instead of @mydomain, but setting
php_value mail.force_extra_parameters "-f http@domain.com"
in httpd-vhosts.conf file did the trick!
@kornrunner:
And it's cool it's that way (though it feels like a hack to me), since I'll be setting it up for every new domain that way (unlesss I find a better solution).
It's not really a hack. It is expected from PHP scripts to set the From: header manually through mail(). Every decent CMS or applications does that and has configuration where you can set it.
The alternative is to force it with the above setting in php.ini.
But Stever is onto something as well, if you check the link you'll see you can set the alias database and rewrite
See, thing is that PHP sends mail by calling sendmail, and sendmail takes -f parameter to specify envelope sender address (which is what you need). Sendmail is basically a MUA while Postfix is MTA, it actually connects to it via port 25 @ localhost.
So conceptually and philosophically, it is the MUA's responsibility to set the envelope from address, thatis application's (PHP). MTA address rewrite would then be a "hack", if observed from the standpoint of separation of concerns.