【问题标题】:PHPMailer SMTP configurationPHPMailer SMTP 配置
【发布时间】:2012-12-24 18:16:16
【问题描述】:

在过去的 2 个小时里,我一直在网上查看是否有其他人遇到过这个问题,而且似乎很多人遇到过这个问题,但没有一个答案对我有用。

SMTP -> FROM SERVER:220 mx.google.com ESMTP vq7sm928004oeb.13 
SMTP -> FROM SERVER: 250-mx.google.com at your service, [50.57.114.141] 250-SIZE 35882577 250-8BITMIME 250-STARTTLS 250 ENHANCEDSTATUSCODES 
SMTP -> FROM SERVER:220 2.0.0 Ready to start TLS 
SMTP -> FROM SERVER: 250-mx.google.com at your service, [50.57.114.141] 250-SIZE 35882577 250-8BITMIME 250-AUTH LOGIN PLAIN XOAUTH XOAUTH2 250 ENHANCEDSTATUSCODES 
SMTP -> FROM SERVER:530-5.5.1 Authentication Required. Learn more at 530 5.5.1 http://support.google.com/mail/bin/answer.py?answer=14257 vq7sm928004oeb.13 
SMTP -> ERROR: MAIL not accepted from server: 530-5.5.1 Authentication Required. Learn more at 530 5.5.1 http://support.google.com/mail/bin/answer.py?answer=14257 vq7sm928004oeb.13 
The following From address failed: my@email.com

$mail->IsSMTP();
$mail->SMTPDebug = 2;
$mail->SMPTAuth = true;
$mail->SMTPSecure = 'tls';
$mail->Host = "smtp.gmail.com";
$mail->Mailer = "smtp";
$mail->Port = 587;
$mail->Username = "my@email.com";
$mail->Password = "password";

我已经尝试了几乎所有 PHPMailer 的设置,但还是不知道哪里出了问题,我需要处理任何服务器设置吗?

我也尝试了普通的 php mail() 函数,但这也不是发送邮件,虽然在使用 Drupal 表单时它只是发送一封电子邮件。

【问题讨论】:

标签: email phpmailer php


【解决方案1】:

首先,您必须配置正确的服务器以发送电子邮件(参见 gmail.com):

SMTP server address: smtp.gmail.com
SMTP user name: Your full Gmail address (e.g. example@gmail.com)
SMTP password: Your Gmail password
SMTP port: 465 or 587
SMTP TLS/SSL required: yes

在 PHPMailer 中:

$mail->SMTPAuth = true; // There was a syntax error here (SMPTAuth)
$mail->SMTPSecure = 'tls';
$mail->Host = "smtp.gmail.com";
$mail->Mailer = "smtp";
$mail->Port = 465;
$mail->Username = "YOU@gmail.com";
$mail->Password = "YOUR_GMAIL_password";

【讨论】:

  • 如果我尝试使用端口 465,我会得到以下信息:SMTP -> FROM SERVER: SMTP -> FROM SERVER: SMTP -> ERROR: EHLO not accepted from server: SMTP -> FROM SERVER: SMTP -> ERROR: HELO not accepted from server: SMTP -> NOTICE: EOF caught while checking if connectedThe following From address failed: gmail@domain.com
【解决方案2】:

我的问题是我使用了两步验证。因此,我必须记住为我的 Google 帐户访问授权访问,然后为我用来发送邮件的域分配一个应用程序专用密码。

【讨论】:

    【解决方案3】:

    刚刚注意到我在 $mail->SMPTAuth = true; 这一行中输入了错误的 SMTP,纠正这个问题解决了我的问题。

    【讨论】:

      【解决方案4】:

      在 php 中设置邮件可能非常困难。你试过使用 port=25 吗?

      【讨论】:

      • 同样的问题,它总是说“FROM SERVER:530-5.5.1 Authentication Required”,这不适用于 Google Apps 地址吗?
      【解决方案5】:

      建议的端口+协议组合对我来说似乎是错误的,因为它与官方phpMailer-wiki不同:

      不要混淆这些模式; 587 端口上的 ssl 或 465 端口上的 tls 不会 工作。

      在 PHPMailer 中:

      $mail->SMTPAuth = true;
      $mail->SMTPSecure = 'tls';
      $mail->Host = "smtp.gmail.com";
      $mail->Mailer = "smtp";
      $mail->Port = 587; //use port 465 when using SMPTSecure = 'ssl'
      $mail->Username = "YOU@gmail.com";
      $mail->Password = "YOUR_GMAIL_password";
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-06-05
        • 1970-01-01
        • 2014-09-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-09-06
        相关资源
        最近更新 更多