“密码未被接受来自服务器:535不正确的认证数据”当使用GMail和phpMailer发送时 [英] "Password not accepted from server: 535 Incorrect authentication data" when sending with GMail and phpMailer

查看:1167
本文介绍了“密码未被接受来自服务器:535不正确的认证数据”当使用GMail和phpMailer发送时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在本地主机上运行相同的php脚本 - 我的PC上装有XAMPP并在托管服务器上运行。它可以在我的电脑上运行,但不能从托管服务器上运行。



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

  SMTP  - >错误:服务器不接受密码:535验证数据不正确
SMTP - >错误:RCPT未从服务器接受:550-请在发送邮件之前打开邮件客户端中的SMTP身份验证或登录到550-IMAP / POP3服务器。 dev.camppage.com 550-(patchvalues.com)[205.234.141.238]:50958不允许在没有验证的情况下通过550中继该服务器。
SMTP错误:以下收件人失败:jdorner4@gmail.com失败

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



以下是代码:

  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; //将GMAIL设置为SMTP服务器
$ mail-> SMTPDebug = 1; //启用SMTP调试信息(用于测试)0 - 无; 1 - 错误&消息; 2 - 仅限消息
$ mail-> SMTPAuth = true; //启用SMTP认证
$ mail-> SMTPSecure =ssl; //为服务器设置前缀
$ mail->端口= 465; //设置SMTP端口
$ mail->用户名= $ email_address; // GMAIL用户名
$ mail->密码= $ email_password; // GMAIL密码
$ mail-> SetFrom($ email_address);
$ mail-> FromName = $ email_name;
$ mail-> AddReplyTo($ email_address,$ email_name);
$ mail-> Subject = $ subject;
$ mail-> MsgHTML($ body);
$ mail-> IsHTML(true); //以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); //发送为HTML

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


$ / code $ / pre
$ b $ TIA



在运行cPanel的WHM的服务器上,它位于WHM的Tweak Settings部分。



启用/禁用 - 选择禁用。



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

I have the same php script running on localhost - my PC with XAMPP and on a hosted server. It works from my PC, but not from the hosted server.

When I send it from the hosted server, I get the following output:

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

I suspect there is a configuration setting that needs to be changed on the server, but I don't know which one. Any advice would be greatly appreciated!

Here is the code:

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

解决方案

The solution was to enable outgoing SMTP from the server settings.

On servers running cPanel's WHM, this is located under WHM's "Tweak Settings" section.

The option is to enable/disable - choose disable.

Caveat: Making this change will redirect outgoing SMTP connections allow accounts to make direct connections which may increase your odds of getting your server blacklisted.

这篇关于“密码未被接受来自服务器:535不正确的认证数据”当使用GMail和phpMailer发送时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆