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.

$ 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

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.

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.

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

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

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.

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

Thanks!

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! :) 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).

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

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct