
我正在將網站移至另一台伺服器,但 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 無論如何為該用戶發送。
後綴配置
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 的經驗,所以我建議你刪除發送郵件。透過此刪除,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、錯誤訊息等)