【问题标题】:How do I fix '530-5.5.1 Authentication Required' error when trying to send e-mail from localhost?尝试从 localhost 发送电子邮件时,如何修复“530-5.5.1 Authentication Required”错误?
【发布时间】:2015-11-08 23:14:21
【问题描述】:

我一直在尝试从在我的本地主机上运行的以下 PHP 脚本发送电子邮件,并使用 G-mail 作为我的 SMTP 中继主机。

<?php
// The message
$message = "Line 1\r\nLine 2\r\nLine 3";

$message = wordwrap($message, 70, "\r\n");

$headers = 'From: <my-email>@gmail.com' . "\r\n" .
    'Reply-To: <my-email>@gmail.com' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

// Send Mail
if (true==mail('<other email>@gmail.com', 'My Subject', $message, $headers, '-f<other email>@gmail.com'))
{
    echo "E-mail successfully sent.";
}
else
{
    echo "E-mail failed.";
}
?>

虽然邮件函数返回 'TRUE',但实际上没有电子邮件被送达,当我查看邮件日志时,我不断收到以下错误:

另外,在查看 mail.log 文件时,记录了以下错误:

Aug 17 22:00:03 unknownf81edfd84850 postfix/smtp[1714]: maps_find: smtp_sasl_passwd: smtp.gmail.com: not found
Aug 17 22:00:03 unknownf81edfd84850 postfix/smtp[1714]: maps_find: smtp_sasl_passwd: smtp.gmail.com:587: not found
Aug 17 22:00:03 unknownf81edfd84850 postfix/smtp[1714]: smtp_sasl_passwd_lookup: no auth info found (sender=`rrodriguez6@unknownf81edfd84850.att.net', host=`smtp.gmail.com')
Aug 17 22:00:03 unknownf81edfd84850 postfix/smtp[1714]: > smtp.gmail.com[173.194.219.108]:587: MAIL FROM:<rrodriguez6@unknownf81edfd84850.att.net> SIZE=389
Aug 17 22:00:03 unknownf81edfd84850 postfix/smtp[1714]: > smtp.gmail.com[173.194.219.108]:587: RCPT TO:<rlrodriguez.rivera@gmail.com>
Aug 17 22:00:03 unknownf81edfd84850 postfix/smtp[1714]: > smtp.gmail.com[173.194.219.108]:587: DATA
Aug 17 22:00:03 unknownf81edfd84850 postfix/smtp[1714]: vstream_fflush_some: fd 15 flush 108
Aug 17 22:00:03 unknownf81edfd84850 postfix/smtp[1714]: vstream_buf_get_ready: fd 15 got 133
Aug 17 22:00:03 unknownf81edfd84850 postfix/smtp[1714]: < smtp.gmail.com[173.194.219.108]:587: 530-5.5.1 Authentication Required. Learn more at
Aug 17 22:00:03 unknownf81edfd84850 postfix/smtp[1714]: < smtp.gmail.com[173.194.219.108]:587: 530 5.5.1  https://support.google.com/mail/answer/14257 j2sm2579221ywj.12 - gsmtp
Aug 17 22:00:03 unknownf81edfd84850 postfix/smtp[1714]: connect to subsystem private/bounce

是否有可能 postfix 无法读取我的 sasl_passwd.db 文件?

感谢您对此的帮助!

-拉蒙

下面是我的 sasl_passwd 文件的内容:

smtp.gmail.com:587 <my gmail account>:�<my gmail password>

另外,我的 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=
# Enable Transport Layer Security (TLS), i.e. SSL.
smtp_use_tls=yes
smtp_tls_security_level=encrypt
tls_random_source=dev:/dev/urandom
smtp_tls_CAfile = /etc/postfix/ssl/cacert.pem
debug_peer_list=smtp.gmail.com
debug_peer_level=3

我注意到的一件事是,当我运行 postmap 以创建 sasl_passwd.db 文件时,我收到以下警告:

postmap: warning: sasl_passwd, line 0: expected format: key whitespace value

我确信我在这里忽略了一些非常简单的问题,但最近几天我一直在努力让这个邮件功能正常工作。

非常感谢您的建议。

【问题讨论】:

  • 使用PHPMailer。它让事情变得容易多了。
  • 谢谢!我尝试使用 PHPMailer,它确实可以创造奇迹。

标签: php email smtp


【解决方案1】:

事实证明,我需要配置我的 Google Apps 帐户,以便他们允许 SMTP 中继。一旦我这样做了,我就可以开始使用 PHPMailer 和 PHP 中的常规邮件功能发送电子邮件了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-06-25
    • 2012-07-28
    • 2023-02-13
    • 1970-01-01
    • 2017-10-30
    • 2012-08-23
    • 1970-01-01
    相关资源
    最近更新 更多