I have a development web server (CentOS LAMP stack) that uses SMTP relays setup in postfix to send email. We use mailgun with multiple users, a setup similar to this, but with specific users instead of just wildcard emails:
/etc/postfix/main.cf
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_auth_enable = yes
sender_dependent_relayhost_maps = hash:/etc/postfix/relayhost_map
smtp_sender_dependent_authentication = yes
smtp_sasl_security_options = noanonymous
relayhost = [smtp.mailgun.org]:587
/etc/postfix/sasl_passwd
# our domains
[email protected] [email protected]:password1
[email protected] [email protected]:password2
[email protected] [email protected]:password3
# in-case we don't have it setup, use a default
#[smtp.mailgun.org]:587 [email protected]:password2
/etc/postfix/relayhost_map
[email protected] [smtp.mailgun.org]:587
[email protected] [smtp.mailgun.org]:587
[email protected] [smtp.mailgun.org]:587
To setup email logging , I am authenticating each developer on the machine with their own SMTP credentials. I want to set it up so that developers don't need to add the additional_headers
or additional_parameters
to get the correct smtp relay match in postfix - and indeed it would take a lot of work to setup different mail headers in code for different developers, especially with versioned code. I digress. This was working fine from postfix's side of things when I use the following:
mail('[email protected]', 'subject', 'message here...', 'From: [email protected]', '[email protected]');
So I then added the following to the vhost configs:
php_admin_value sendmail_path "/usr/sbin/sendmail -t -i [email protected]"
which successfully allowed me to get rid of the -f
additional_parameter
and still send properly. Then I added the following:
php_value sendmail_from "[email protected]"
In a phpinfo()
dump I see the local value for sendmail_from
is set correctly, however now when I send the email it comes up as:
[email protected] on behalf of Apache
It seems as if the correct sender (MIME, not envelope, as postfix recognises the authentication and gives 250 Great success). With postfix logging on verbose, I see only references to the correct email from the sender input attribute.
In mailgun, I see the following information from the log, however, for the email when the From: [email protected]
isn't used:
...
"envelope": {
"transport": "smtp",
"sender": "[email protected]",
"sending-ip": "x.x.x.x",
"targets": "[email protected]"
},
"message": {
"headers": {
"to": "[email protected]",
"message-id": "[email protected]",
"from": "[email protected] (Apache)",
"subject": "Debug Test"
},
"attachments": [],
"recipients": [
"[email protected]"
],
"size": 654
},
...
What's interesting is the same log for when From: [email protected]
is present, the message->headers->from
is set correcetly to [email protected]
without the (Apache)
addition. Surely this means that it's PHP's fault and that PHP is not utilising the sendmail_from
value properly?
So with all this in mind, my resulting question is how can I set the default MIME Sender (From header) in PHP, apart from in the mail()
function? Have I missed something with my method/config above, or is it just plain impossible? I'm happy to think outside the box a little, being that this will help save time for the reason we want this feature.
mail()
wrapper is because of the number of sites and different codebases they all use - this is definitely something long-term I'd like, but not an option yet. We can ignore the -f stuff altogether because as I said the envelope sender is working just fine with my sendmail path config. But the sendmail_from is being ignored altogether, therefore MIME from isn't being set. sendmail_from isn't set in php.ini, only in the local config. Either way it seems to be disregarded. Maybe a bug? I will try other versions of PHP. – Susansusana