【问题标题】:using php mailer mail send from localhost xamp successfully but failed to sending in production windows hosting使用 phpmailer 邮件从 localhost xampp 成功发送,但无法在生产 Windows 托管中发送
【发布时间】:2019-03-29 05:27:50
【问题描述】:

我使用 PHP 邮件程序发送电子邮件 在我的 localhost XAMPP 服务器中,使用以下附加代码脚本(使用 PHP 邮件程序)成功发送电子邮件 但在生产服务器中托管的 Windows 2012 中,它会显示错误

SMTP Error: Could not authenticate
SMTP connect() failed. 

这是我的脚本

<?php

ini_set('memory_limit', '-1');
ini_set('max_execution_time', 0);

require_once('PHPMailer-master/class.phpmailer.php');
require_once('PHPMailer-master/class.smtp.php');
$email = new PHPMailer();
$email->MailerDebug = true;
$mail = new PHPMailer;
$mail->SMTPDebug = 2;

$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'ssl';
$mail->Port = 465;


/*$mail->SMTPAuth = false;
$mail->SMTPSecure = false;*/

$mail->Username = 'someusername@gmail.com';
$mail->Password = 'password';
$mail->setFrom('someusername@gmail.com', 'hello');
$mail->addAddress('testaddress@gmail.com');
$mail->addReplyTo('someusername@gmail.com');
$mail->isHTML(true);
$mail->Subject = 'the subject of the e-mail';
$mail->Body = 'The body of the email';
//  $mail->AltBody = 'Alternative'; // this is mostly sent to your own mail

if(!$mail->send()) {
    echo 'Message could not be sent.';
    echo 'Mailer Error: <pre>' . $mail->ErrorInfo;
} else {
    echo 'Message has been sent';
}


?>

错误信息

我还在谷歌邮件设置中启用了安全性较低的应用选项

【问题讨论】:

  • 请不要发布文字图片,而是发布文字。

标签: php windows email phpmailer


【解决方案1】:

首先,你使用的是旧版本的 PHPMailer,所以upgrade

错误消息中有一些消息和链接可以告诉您问题,首先是在 Google 上,还有一个指向 PHPMailer 故障排除指南的链接,其中描述了exactly this problem in great detail。有这些链接是有原因的。

当它说“请通过您的网络浏览器登录,然后重试”时,它的意思正是它所说的:您应该使用普通的网络浏览器登录您的 gmail 帐户,然后再次尝试您的脚本。原因是 google 将您的网络登录视为确认您的帐户被合法访问的一种方式。

按照指南的其余部分进行操作,它将解决您的问题。

您还泄露了您的 gmail 帐户的 ID 和密码,所以我建议您更改它们。

【讨论】:

  • 我在邮件发送成功后更改了我的gmail帐户密码
【解决方案2】:

这个配置对我有用:

$mail->Host = 'smtp.googlemail.com';
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
$mail->SMTPAuth = true;

【讨论】:

  • 你需要说明为什么你认为这可能会奏效——尽管它不会,并且与失败的原因无关。
猜你喜欢
  • 2013-07-15
  • 2012-01-21
  • 2018-10-16
  • 1970-01-01
  • 2017-09-29
  • 2018-05-16
  • 1970-01-01
  • 2015-12-16
  • 2016-12-11
相关资源
最近更新 更多