我正在将网站移至另一台服务器,但遇到了 PHP 邮件问题。但仅限于向主机域发送邮件时,例如[电子邮件保护]。
mail($send_to, 'Web contact' ,$message,null,"-r [email protected]");
我发送邮件的唯一方法是添加 -r 标志,在标志后输入什么电子邮件地址似乎并不重要。
这是从 Centos 5 到 6 的迁移,我相信邮件现在使用 Postfix 而不是 sendMail。
是否有一个 Postfix 设置可以让我不再需要在每次调用邮件功能时添加此标志?
此外,如果我无法解决这个问题,有没有办法强制使用 sendMail 而不是使用 Postfix?
我应该提到我知道邮件是在内部路由的,如日志所示:
编辑
这是没有标志的失败尝试
May 14 16:13:12 test sendmail[10244]: t4EFDCLq010244: from=apache, size=169, class=0, nrcpts=1, msgid=<[email protected]>, relay=apache@localhost
May 14 16:13:12 test postfix/smtpd[10245]: connect from localhost[127.0.0.1]
May 14 16:13:12 test postfix/smtpd[10245]: 9EFB3256738: client=localhost[127.0.0.1]
May 14 16:13:12 test postfix/cleanup[10248]: 9EFB3256738: message-id=<[email protected]>
May 14 16:13:12 test sendmail[10244]: t4EFDCLq010244: [email protected], ctladdr=apache (48/48), delay=00:00:00, xdelay=00:00:00, mailer=relay, pri=30169, relay=[127.0.0.1] [127.0.0.1], dsn=2.0.0, stat=Sent (Ok: queued as 9EFB3256738)
May 14 16:13:12 test postfix/qmgr[10102]: 9EFB3256738: from=<[email protected]>, size=592, nrcpt=1 (queue active)
May 14 16:13:12 test postfix/smtpd[10245]: disconnect from localhost[127.0.0.1]
May 14 16:13:12 test postfix/smtp[10249]: 9EFB3256738: to=<[email protected]>, relay=mail.example.com[748.31.105.444]:25, delay=0.1, delays=0.04/0.01/0.01/0.03, dsn=5.0.0, status=bounced (host mail.example.com[748.31.105.444] said: 550-Verification failed for <[email protected]> 550-No Such User Here" 550 Sender verify failed (in reply to RCPT TO command))
May 14 16:13:12 test postfix/cleanup[10248]: B47B625675D: message-id=<[email protected]>
May 14 16:13:12 test postfix/bounce[10250]: 9EFB3256738: sender non-delivery notification: B47B625675D
May 14 16:13:12 test postfix/qmgr[10102]: B47B625675D: from=<>, size=2524, nrcpt=1 (queue active)
May 14 16:13:12 test postfix/qmgr[10102]: 9EFB3256738: removed
May 14 16:13:12 test postfix/smtp[10249]: B47B625675D: to=<[email protected]>, relay=mail.example.com[748.31.105.444]:25, delay=0.03, delays=0/0/0.01/0.02, dsn=5.0.0, status=bounced (host mail.example.com[748.31.105.444] said: 550 No Such User Here" (in reply to RCPT TO command))
May 14 16:13:12 test postfix/qmgr[10102]: B47B625675D: removed
这是旗帜
May 14 16:13:23 test sendmail[10251]: t4EFDN45010251: Authentication-Warning: example.com: apache set sender to [email protected] using -r
May 14 16:13:23 test sendmail[10251]: t4EFDN45010251: [email protected], size=169, class=0, nrcpts=1, msgid=<[email protected]>, relay=apache@localhost
May 14 16:13:23 test postfix/smtpd[10245]: connect from localhost[127.0.0.1]
May 14 16:13:23 test postfix/smtpd[10245]: 3B3EF256738: client=localhost[127.0.0.1]
May 14 16:13:23 test postfix/cleanup[10248]: 3B3EF256738: message-id=<[email protected]>
May 14 16:13:23 test postfix/qmgr[10102]: 3B3EF256738: from=<[email protected]>, size=662, nrcpt=1 (queue active)
May 14 16:13:23 test sendmail[10251]: t4EFDN45010251: [email protected], [email protected] (48/48), delay=00:00:00, xdelay=00:00:00, mailer=relay, pri=30169, relay=[127.0.0.1] [127.0.0.1], dsn=2.0.0, stat=Sent (Ok: queued as 3B3EF256738)
May 14 16:13:23 test postfix/smtpd[10245]: disconnect from localhost[127.0.0.1]
May 14 16:13:24 test postfix/smtp[10249]: 3B3EF256738: to=<[email protected]>, relay=mail.example.com[748.31.105.444]:25, delay=1.4, delays=0.03/0/0.01/1.3, dsn=2.0.0, status=sent (250 OK id=1Ysup9-0001Rr-Jv)
May 14 16:13:24 test postfix/qmgr[10102]: 3B3EF256738: removed
问题似乎是用户 apache 被 Postfix 退回,理想情况下我希望 Postfix 无论如何都向该用户发送。
Postfix 配置
alias_database = hash:/etc/aliases
alias_maps = hash:/etc/aliases
command_directory = /usr/sbin
config_directory = /etc/postfix
daemon_directory = /usr/libexec/postfix
data_directory = /var/lib/postfix
debug_peer_level = 2
html_directory = no
inet_interfaces = localhost
inet_protocols = all
mail_owner = postfix
mailq_path = /usr/bin/mailq.postfix
manpage_directory = /usr/share/man
mydestination = localhost.$mydomain
mydomain = example.com
newaliases_path = /usr/bin/newaliases.postfix
queue_directory = /var/spool/postfix
readme_directory = /usr/share/doc/postfix-2.6.6/README_FILES
sample_directory = /usr/share/doc/postfix-2.6.6/samples
sendmail_path = /usr/sbin/sendmail.postfix
setgid_group = postdrop
unknown_local_recipient_reject_code = 550
答案1
首先你需要删除一个 MTA。一个系统中有两个 MTA 可能会产生意想不到的结果。因为我只对 postfix 有经验,所以我建议你刪除 sendmail. 删除后,mail
命令将使用 postfix 而不是 sendmail 作为默认代理。
yum remove sendmail
其次,您可以设置php.ini 中的默认 sendmail 参数和sendmail_path
参数例如
sendmail_path = '/usr/sbin/sendmail -t -i -f [email protected]'
PS:根据本手册页,-r
flag 是 flag 的过时形式-f
。因此,我更喜欢使用-f
。
第三关于你的评论:
从日志中我可以看到它正在反弹,因为[电子邮件保护]不存在。我已添加该设置,这解决了问题,但 Postfix 中是否有一个设置可以添加,以便[电子邮件保护]不需要创建?
此错误消息
550-验证失败,550-此处无此用户”550 发件人验证失败
不是由 postfix 抛出的。电子邮件已被mail.**z*.net
运行进出口你需要和 Exim 管理员谈谈为什么它会有这样的行为
答案2
在您的中main.cf
有一个名为的参数mydestination
。删除那里的域名形式,这样发送到该域的邮件将不再在本地传递。
前:
mydestination = $myhostname, $mydomain
后:
mydestination = $myhostname
$myhostname
应该保留在此列表中以用于内部邮件(cron,apt,错误消息等)