【问题标题】:"Password not accepted from server: 535 Incorrect authentication data" when sending with GMail and phpMailer使用 GMail 和 phpMailer 发送时“服务器不接受密码:535 验证数据不正确”
【发布时间】:2012-12-27 03:54:14
【问题描述】:

我在本地主机上运行相同的 php 脚本 - 我的带有 XAMPP 的 PC 和托管服务器上。它适用于我的 PC,但不适用于托管服务器。

当我从托管服务器发送它时,我得到以下输出:

SMTP -> ERROR: Password not accepted from server: 535 Incorrect authentication data  
SMTP -> ERROR: RCPT not accepted from server: 550-Please turn on SMTP Authentication in your mail client, or login to the 550-IMAP/POP3 server before sending your message. dev.camppage.com 550-(patchvalues.com) [205.234.141.238]:50958 is not permitted to relay through 550 this server without authentication.  
SMTP Error: The following recipients failed: jdorner4@gmail.com FAILED

我怀疑服务器上有一个配置设置需要更改,但我不知道是哪一个。任何建议将不胜感激!

代码如下:

function send_gmail ($recipients, $subject, $message, $attachment_filenames = array()) 
{
  global $email_address, $email_password, $email_name;
  require_once ($_SERVER['DOCUMENT_ROOT']. '/php/PHPMailer/class.phpmailer.php');   

  $body  = $message;
  $body  = str_replace("\\", '', $body);
  $mail = new PHPMailer();
  $mail->CharSet = "UTF-8";
  $mail->IsSMTP();
  $mail->Host       = "smtp.gmail.com";      // sets GMAIL as the SMTP server
  $mail->SMTPDebug  = 1;                     // enables SMTP debug information (for testing) 0 - none; 1 - errors & messages; 2 - messages only
  $mail->SMTPAuth   = true;                  // enable SMTP authentication
  $mail->SMTPSecure = "ssl";                 // sets the prefix to the servier
  $mail->Port       = 465;                   // set the SMTP port
  $mail->Username   = $email_address;  // GMAIL username
  $mail->Password   = $email_password; // GMAIL password
  $mail->SetFrom($email_address);
  $mail->FromName   = $email_name;
  $mail->AddReplyTo($email_address,$email_name);
  $mail->Subject    = $subject;
  $mail->MsgHTML($body);
  $mail->IsHTML(true); // send as HTML

  if (isset ($recipients[0]))
  {
    foreach ($recipients AS $to)
    {
        $to_pieces = explode (",", $to, 2);
        $to_email = trim ($to_pieces[0]);
        if (isset ($to_pieces[1]))
            $to_name = trim ($to_pieces[1]);
        else
            $to_name = " ";
        $mail->AddAddress($to_email, $to_name);
    }
    $mail->IsHTML(true); // send as HTML

    if ($mail->Send()){
        return TRUE;
    } else {
        return FALSE;
    }
} 
else 
{
    return FALSE;
}
}

TIA

【问题讨论】:

标签: php gmail phpmailer


【解决方案1】:

我写这个答案是因为评论只支持文本并且不提供上传图片的选项。 @John Dorner 给出的答案是正确的。

我发布此图片以供快速参考。这只是为了让任何来到这里的未来用户都可以快速解决这个问题。

注意:这种问题通常发生在您设置服务器时,并且名称服务器可能由域服务提供商管理,并且服务器仅通过带有某个 IP 地址的记录条目来指向.在这种情况下,域所有者可能正在使用 GSuit 并在该域的名称记录中添加了少量 MX 记录。在这种情况下,通过 WHM 创建的电子邮件帐户发送电子邮件可能无法正常工作,因为服务器上缺少 MX 记录条目并且该 MX 记录条目存在于域服务提供商处。在这种情况下,最好使用第三方电子邮件服务提供商,例如 MailGun、MailTrap 或 MailChimp。

【讨论】:

    【解决方案2】:

    这与 WHM/cPanel 相关,您可以执行与上一个答案相同的操作,也可以通过键入此命令从 shell 中执行操作

    /scripts/smtpmailgidonly off
    

    你应该得到

    "SMTP Mail protection has been disabled.  All users may make outbound smtp connections."
    

    更多阅读在这里https://forums.cpanel.net/threads/cant-enable-smtp-restrictions.360971/

    【讨论】:

    • 你就是这样救了我的命
    【解决方案3】:

    解决方案是从服务器设置中启用传出 SMTP。

    在运行 cPanel 的 WHM 的服务器上,这位于 WHM 的“调整设置”部分下。

    选项是启用/禁用 - 选择禁用。

    警告:进行此更改将重定向传出 SMTP 连接,允许帐户进行直接连接,这可能会增加您将服务器列入黑名单的几率。

    【讨论】:

    • 你是救生员。我正在使用 CentOs 6 Login to CPanel > Tweak Settings > All> "Restrict outgoing SMTP to root, exim, and mailman (FKA SMTP Tweak)"
    • 老兄,你是救命稻草,当你不知从何而来,穿着你的英雄套装来救我时,我就在沮丧的行刑队面前。谢谢
    • 是的。也拯救了我的皮肤。谢谢!
    • 金金属。我花了一年多的时间,就这么简单。还要感谢@Telvin Nguyen,让事情变得更简单
    • 是否有人能够提供更多信息,说明为什么更改此设置会增加您的 IP 被列入黑名单的机会?如果需要更改此设置,我们如何在 WHM 服务器上使用带有 Gmail 帐户的 PhpMailer 而不会将我们的 IP 列入黑名单?我已经为此奋斗了几个月,不敢相信没有合乎逻辑的解决方案。谢谢,
    猜你喜欢
    • 2018-02-07
    • 2016-12-10
    • 2020-12-16
    • 2017-11-29
    • 2020-09-29
    • 1970-01-01
    • 2017-11-11
    • 1970-01-01
    • 2014-12-11
    相关资源
    最近更新 更多