我有一个开发Web服务器(CentOS LAMP堆栈),它使用postfix中的SMTP中继设置来发送电子邮件.我们使用带有多个用户的mailgun,类似于此的设置,但是使用特定用户而不仅仅是通配符电子邮件:
/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
/等/后缀/ sasl_passwd
# our domains no-reply@domain.com postmaster@domain.com:password1 info@domain2.com postmaster@domain2.com:password2 support@domain3.com postmaster@domain3.com:password3 # in-case we don't have it setup, use a default #[smtp.mailgun.org]:587 postmaster@domain2.com:password2
/等/后缀/ relayhost_map
no-reply@domain.com [smtp.mailgun.org]:587 info@domain2.com [smtp.mailgun.org]:587 support@domain3.com [smtp.mailgun.org]:587
要设置电子邮件日志记录,我使用自己的SMTP凭据验证计算机上的每个开发人员.我想设置它,以便开发人员不需要在postfix中添加additional_headers
或additional_parameters
获取正确的smtp中继匹配 - 事实上,在代码中为不同的开发人员设置不同的邮件头需要做很多工作,特别是对于版本化的码.我离题了.当我使用以下内容时,这在postfix的方面工作得很好:
mail('email@address.tld', 'subject', 'message here...', 'From: noreply@domain.com', '-fnoreply@domain.com');
所以我然后将以下内容添加到vhost配置中:
php_admin_value sendmail_path "/usr/sbin/sendmail -t -i -fnoreply@domain.com"
这成功地让我摆脱了-f
additional_parameter
仍然正确发送.然后我添加了以下内容:
php_value sendmail_from "noreply@domain.com"
在phpinfo()
转储中,我看到sendmail_from
正确设置了本地值,但是现在当我发送电子邮件时,它显示为:
None@domain.com代表Apache
似乎正确的发件人(MIME,而不是信封,因为postfix识别身份验证并获得250次成功).使用详细的postfix登录,我只看到来自sender输入属性的正确电子邮件的引用.
在mailgun中,我看到日志中的以下信息,但是,对于From: noreply@domain.com
未使用的电子邮件:
... "envelope": { "transport": "smtp", "sender": "noreply@domain.com", "sending-ip": "x.x.x.x", "targets": "email@address.tld" }, "message": { "headers": { "to": "email@address.tld", "message-id": "2014061111016.ABC1D23456E@domain.com", "from": "noreply@domain.com (Apache)", "subject": "Debug Test" }, "attachments": [], "recipients": [ "email@address.tld" ], "size": 654 }, ...
有趣的是相同的日志,当From: noreply@domain.com
是目前,message->headers->from
被correcetly设置为noreply@domain.com
不(Apache)
增加.当然这意味着它是PHP的错误并且PHP没有sendmail_from
正确使用该值?
所以考虑到所有这些,我得到的问题是如何在PHP中设置默认的MIME发送者(From头),除了在mail()
函数中?我上面的方法/配置错过了什么,或者它是否完全不可能?我很乐意在盒子外面思考一下,因为我们想要这个功能,这将有助于节省时间.