【问题标题】:PHPMailer SMTP Error: Could not authenticate Mercury localhostPHPMailer SMTP 错误:无法验证 Mercury localhost
【发布时间】:2017-08-19 19:51:19
【问题描述】:

目前我正在本地测试我的电子邮件格式和电子邮件发送。我使用 XAMPP 并“设置”了 Mercury 邮件服务器。我没有更改任何内容并创建了一个新用户。

这是本地用户的照片:

然后,我在 PHP 中有这个(不是所有的代码,而是重要的部分):

$mailer = new mailer\Mailer();
$mailer->setCustomSettings();
// Some addAddress, From, subject and content variables are set here....
$mailer->send();

然后setCustomSettings 看起来像这样:

public function setCustomSettings() {
    $this->CharSet = 'UTF-8';
    $this->isSMTP();
    $this->Host = 'localhost';
    $this->SMTPAuth = true;
    $this->Username = 'Admin';
    $this->Password = '*******';

    //$this->SMTPSecure = 'tls';
    $this->Port = 25;
    $this->imapHost = '127.0.0.1';
}

现在,我希望它会起作用,但不幸的是它没有。我收到以下错误:

<b>Fatal error</b>:  Uncaught exception 'mailer\phpmailerException' with message 'SMTP Error: Could not authenticate.' in D:\xampp\htdocs\FOLDER\classes\mailer\PHPMailer.php:1352

我知道我的密码是正确的,你可以看到用户存在,我可以在我的电子邮件上登录 Roundcube。

使用SMTPDebug 我得到以下输出:

2017-03-27 07:57:18 SERVER -> CLIENT: 220 localhost ESMTP server ready.
2017-03-27 07:57:18 CLIENT -> SERVER: EHLO SOMENAME.local
2017-03-27 07:57:18 SERVER -> CLIENT: 250-localhost Hello SOMENAME.local; ESMTPs are:
                                  250-TIME
                                  250-SIZE 0
                                  250 HELP
2017-03-27 07:57:18 CLIENT -> SERVER: QUIT
2017-03-27 07:57:18 SERVER -> CLIENT: 221 localhost Service closing channel.
2017-03-27 07:57:18 SMTP Error: Could not authenticate.

【问题讨论】:

  • 尝试使用$this-&gt;SMTPDebug = 2;启用调试器
  • 查看我编辑后的输出。
  • 尝试指定Username = "root@localhost"
  • 还是不行。

标签: php email phpmailer


【解决方案1】:

这表明您的邮件服务器上缺少某些内容。这是它说它支持的功能列表:

250-TIME
250-SIZE 0
250 HELP

请注意,此列表不包含AUTH 扩展名,但您已要求 PHPMailer 进行身份验证,但它不能,因为您的服务器不支持身份验证,所以它放弃了。作为比较,这是 Gmail 所说的(在 STARTTLS 之后):

250-smtp.gmail.com at your service
250-SIZE 35882577
250-8BITMIME
250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH
250-ENHANCEDSTATUSCODES
250-PIPELINING
250-CHUNKING
250 SMTPUTF8

你可以看到它列出了一整套AUTH机制。

您应该能够通过简单地禁用身份验证来解决此问题:

$this->SMTPAuth = false;

或通过更改邮件服务器的配置以提供身份验证。

我在这里,你为什么不把你的setCustomSettings()方法里的东西放到一个构造方法中,这样你就不需要调用它了?

【讨论】:

  • 我还没改,我只是先尝试​​一下。我没有做那个功能。我知道当$this-&gt;SMTPAuth 为假时它会起作用,但我宁愿把它打开。我看看能不能在 Mercury 上为 AUTH 找到一些东西。
猜你喜欢
  • 2016-01-16
  • 1970-01-01
  • 2023-03-31
  • 2011-04-26
  • 2016-07-14
  • 2018-08-04
  • 1970-01-01
  • 2015-07-23
相关资源
最近更新 更多