我试图设置 postfix MTA 以使用 PHP 中的 mail() 函数。在 Mac OSX sierra PHP 版本 7.1.0 上使用 MAMP 4.1 免费版本 我对使用 MAMP PRO 和第三方库(如 swiftMailer)不感兴趣,因为我想坚持基础知识。
截至目前,我已更新完成以下操作:
使用我的凭据创建了一个名为 sasl_passwd 的文件:
[smtp.gmail.com]:587 [email protected]:mypassword
然后使用以下命令:
sudo postmap /etc/postfix/sasl_passwd sudo chgrp postfix sasl_passwd* sudo chmod 0640 sasl_passwd* sudo postmap -q [smtp.gmail.com]:587 sasl_passwd
打开 /etc/postfix/ 中的 main.cf 并在末尾添加以下行
#Gmail SMTP relayhost=smtp.gmail.com:587 # Enable SASL authentication in the Postfix SMTP client. smtp_sasl_auth_enable=yes smtp_sasl_password_maps=hash:/etc/postfix/sasl_passwd smtp_sasl_security_options=noanonymous smtp_sasl_mechanism_filter=plain # Enable Transport Layer Security (TLS), i.e. SSL. smtp_use_tls=yes smtp_tls_security_level=encrypt tls_random_source=dev:/dev/urandom
重新启动并刷新 Postfix 服务
尝试从终端发送邮件,并检查终端本身的邮件,发现以下回复:
From MAILER-DAEMON Thu Feb 9 14:53:14 2017 X-Original-To: [email protected] Delivered-To: [email protected] Date: Thu, 9 Feb 2017 14:53:14 +0530 (IST) From: [email protected] (Mail Delivery System) Subject: Undelivered Mail Returned to Sender To: [email protected] Auto-Submitted: auto-replied MIME-Version: 1.0 Content-Type: multipart/report; report-type=delivery-status; boundary="CD41810841CF.1486632194/MacBook-Pro.local" This is a MIME-encapsulated message. --CD41810841CF.1486632194/MacBook-Pro.local Content-Description: Notification Content-Type: text/plain; charset=us-ascii This is the mail system at host MacBook-Pro.local. I'm sorry to have to inform you that your message could not be delivered to one or more recipients. It's attached below. For further assistance, please send mail to postmaster. If you do so, please include this problem report. You can delete your own text from the attached returned message. The mail system <[email protected]>: host smtp.gmail.com[74.125.200.109] said: 530-5.5.1 Authentication Required. Learn more at 530 5.5.1 https://support.google.com/mail/?p=WantAuthError a25sm27067419pgd.26 - gsmtp (in reply to MAIL FROM command) --CD41810841CF.1486632194/MacBook-Pro.local Content-Description: Delivery report Content-Type: message/delivery-status Reporting-MTA: dns; MacBook-Pro.local X-Postfix-Queue-ID: CD41810841CF X-Postfix-Sender: rfc822; [email protected] Arrival-Date: Thu, 9 Feb 2017 14:53:11 +0530 (IST) Final-Recipient: rfc822; [email protected] Original-Recipient: rfc822;[email protected] Action: failed Status: 5.5.1 Remote-MTA: dns; smtp.gmail.com Diagnostic-Code: smtp; 530-5.5.1 Authentication Required. Learn more at 530 5.5.1 https://support.google.com/mail/?p=WantAuthError a25sm27067419pgd.26 - gsmtp --CD41810841CF.1486632194/MacBook-Pro.local Content-Description: Undelivered Message Content-Type: message/rfc822 Return-Path: <[email protected]> Received: by MacBook-Pro.local (Postfix, from userid 501) id CD41810841CF; Thu, 9 Feb 2017 14:53:11 +0530 (IST) To: [email protected] Subject: testing Message-Id: <[email protected]> Date: Thu, 9 Feb 2017 14:53:11 +0530 (IST) From: [email protected] (Admin) Thu Feb 9 14:53:11 IST 2017 --CD41810841CF.1486632194/MacBook-Pro.local-- acBook-Pro.local--
为了解决这个问题,我尝试允许访问 Gmail 上不太安全的应用程序。打开它。仍然没有成功。
尝试查看 /var/log/mail,我看不到邮件日志。我在同一目录中创建了一个文件 mail.log,它没有注册日志。我使用终端重新启动了 rsyslog。还是行不通。
发布这篇文章我想在我的 PHP 脚本中使用 mail() 函数,并相应地在 PHP.ini 中进行更改,如果可能的话,请建议同样的说明。