Linode Forum
https://forum.linode.com/

postfix, php mail(), google apps, virtual hosts [SOLVED]
https://forum.linode.com/viewtopic.php?f=11&t=4944
Page 1 of 1

Author:  kornrunner [ Tue Dec 08, 2009 7:12 pm ]
Post subject:  postfix, php mail(), google apps, virtual hosts [SOLVED]

I need some help here. I've set up postfix as a null client, and searched whole email/smtp forum, but couldn't find any solution.

Code:
$ posconf -n

says:
Code:
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

Code:
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 sendmail_from didn't help (via ini_set, or via .htaccess php_value). What am I missing in my configuration?

Author:  Azathoth [ Tue Dec 08, 2009 7:31 pm ]
Post subject: 

In PHP's mail() function you can set additional headers "From: your@address.com\r\n", that's the most straightforward way.

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.

Author:  kornrunner [ Tue Dec 08, 2009 7:49 pm ]
Post subject: 

Thanks for the reply! As I've said, I've tried with sendmail_from, but as you have said - that option is ignored on Linux systems.

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.

Author:  Azathoth [ Tue Dec 08, 2009 8:19 pm ]
Post subject: 

I just checked the docs, there's mail.force_extra_parameters php.ini directive which acts as fifth parameter of mail(). So

mail.force_extra_parameters = "-f your@name.com"

But you have to set that in php.ini, afaik you can't set it via .htaccess.

Author:  Stever [ Tue Dec 08, 2009 8:51 pm ]
Post subject:  Re: postfix, php mail() & google apps on virtual hosts

kornrunner wrote:
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.

http://www.postfix.org/postconf.5.html#myorigin

Author:  kornrunner [ Wed Dec 09, 2009 3:40 am ]
Post subject: 

Thanks!

Removing myorigin from main.cf resulted in all mail to be sent from @myhostname instead of @mydomain, but setting

Code:
php_value mail.force_extra_parameters "-f http@domain.com"


in httpd-vhosts.conf file did the trick! :) 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).

Author:  Azathoth [ Wed Dec 09, 2009 3:56 am ]
Post subject: 

kornrunner wrote:
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 php_user@yourdomain.com to whatever@anywhere.com.

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.

Page 1 of 1 All times are UTC-04:00
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/