php 使用 GMail 和 phpMailer 发送时“服务器不接受密码:535 验证数据不正确”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14297264/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
"Password not accepted from server: 535 Incorrect authentication data" when sending with GMail and phpMailer
提问by John Dorner
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.
我在本地主机上运行了相同的 php 脚本——我的电脑和 XAMPP 和托管服务器上。它适用于我的 PC,但不适用于托管服务器。
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: [email protected] 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
TIA
回答by John Dorner
The solution was to enable outgoing SMTP from the server settings.
解决方案是从服务器设置启用传出 SMTP。
On servers running cPanel's WHM, this is located under WHM's "Tweak Settings" section.
在运行 cPanel 的 WHM 的服务器上,这位于 WHM 的“调整设置”部分下。
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.
警告:进行此更改将重定向传出 SMTP 连接,允许帐户进行直接连接,这可能会增加您将服务器列入黑名单的几率。
回答by Nassim
this is related to WHM/cPanel, you can do the same thing as in the previous answer or from shell by typing this
这与WHM/cPanel相关,您可以通过键入以下内容来执行与上一个答案或从 shell 中相同的操作
/scripts/smtpmailgidonly off
you should get
你应该得到
"SMTP Mail protection has been disabled. All users may make outbound smtp connections."
more reading here https://forums.cpanel.net/threads/cant-enable-smtp-restrictions.360971/
更多阅读在这里https://forums.cpanel.net/threads/cant-enable-smtp-restrictions.360971/

