我在localhost上运行相同的php脚本 - 我的PC与XAMPP和托管服务器上运行。它适用于我的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
答案 0 :(得分:47)
解决方案是从服务器设置启用传出SMTP。
在运行cPanel WHM的服务器上,它位于WHM的“调整设置”部分下。
选项是启用/禁用 - 选择禁用。
警告:进行此更改将重定向外发SMTP连接,允许帐户建立直接连接,这可能会增加将服务器列入黑名单的几率。
答案 1 :(得分:4)
this is related to WHM/cPanel , you can do the same thing as in the previous answer or from shell by typing this
/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/
答案 2 :(得分:0)
我写这个答案是因为评论只支持文本,不提供上传图片的选项。 @John Dorner 给出的答案是正确的。
我张贴这张图片是为了快速参考。这只是为了以后来这里的任何用户都可以快速解决此问题。
注意:这种问题通常发生在您设置服务器时,可能域名服务器由域服务提供商管理,而服务器仅指向带有某个 IP 地址的记录条目.在这种情况下,域所有者可能正在使用 GSuit 并在该域的名称记录中添加了少量 MX 记录。在这种情况下,通过 WHM 创建的电子邮件帐户发送电子邮件可能无法正常工作,因为服务器上缺少 MX 记录条目并且该 MX 记录条目存在于域服务提供商处。在这种情况下,您最好使用第三方电子邮件服务提供商,例如 MailGun、MailTrap 或 MailChimp。