沃梦达 / 编程问答 / php问题 / 正文

PHP 致命错误:“Swift_TransportException"和消息“无法在 SMTP 服务器上进行身份验证"

PHP Fatal error: #39;Swift_TransportException#39; with message #39;Failed to authenticate on SMTP server(PHP 致命错误:“Swift_TransportException和消息“无法在 SMTP 服务器上进行身份验证)

本文介绍了PHP 致命错误:“Swift_TransportException"和消息“无法在 SMTP 服务器上进行身份验证"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道以前有人问过这个问题,并且我已经阅读了那里的所有帖子,但我仍然找不到解决方案.

I know this question's been asked before and I've read all the posts out there, but I still can't find a solution to this.

我有一台安装了 wamp 的 Windows 机器.当我尝试通过谷歌的 SMTP 服务器发送一封简单的电子邮件时,一切正常.但是,当我将相同的脚本复制到 Ubuntu 12 机器时,它给了我这个错误:

I have a windows machine with wamp installed on it. When I try to send a simple email via google's SMTP server everything works fine. Though, when I copy that same script to an Ubuntu 12 machine, it gives me that error:

PHP Fatal error:  Uncaught exception 'Swift_TransportException' with message 'Failed to authenticate on SMTP server with username "xxx@gmail.com" using 2 possible authenticators' in /home/TestMail/SwiftMail/lib/classes/Swift/Transport/Esmtp/AuthHandler.php:171
Stack trace:
/home/TestMail/SwiftMail/lib/classes/Swift/Transport/EsmtpTransport.php(289): Swift_Transport_Esmtp_AuthHandler->afterEhlo(Object(Swift_SmtpTransport))
/home/TestMail/SwiftMail/lib/classes/Swift/Transport/AbstractSmtpTransport.php(114): Swift_Transport_EsmtpTransport->_doHeloCommand()
/home/TestMail/SwiftMail/lib/classes/Swift/Mailer.php(76): Swift_Transport_AbstractSmtpTransport->start()
/home/TestMail/testmail.php(73): Swift_Mailer->send(Object(Swift_Message))
thrown in /home/TestMail/SwiftMail/lib/classes/Swift/Transport/Esmtp/AuthHandler.php on line 171

这就是我初始化传输的方式:

That's how I initialize the transport:

$transport = Swift_SmtpTransport::newInstance('smtp.gmail.com', 465, 'ssl')

我尝试在端口 465 上远程登录到 smtp.gmail.com 并且工作正常,所以它一定不是防火墙问题.

I've tried to telnet to smtp.gmail.com on port 465 and it worked fine, so it must not be a firewall issue.

我使用 PHP 启用了 SSL.我尝试使用不同的邮件服务器发送带有和不带有 SSL 的两封单独的邮件,一切都像魅力一样.只有谷歌的邮件让我生气.

I have SSL enabled with PHP. I tried to send two separate mails with and without SSL with a different mail server and everything worked like charm. It is only google's mail that gets me mad.

这里欢迎任何想法.

我的整个php代码:

<?php
require_once 'SwiftMail/lib/swift_required.php';
// Create the Transport
$transport = Swift_SmtpTransport::newInstance('smtp.gmail.com', 465, 'ssl')
  ->setUsername('xxx@gmail.com')
  ->setPassword('xxx');

// Create the Mailer using your created Transport
$mailer = Swift_Mailer::newInstance($transport);

$htmlbody = 'some html here';

// Create a message
$message = Swift_Message::newInstance('without head')
    ->setFrom(array('<from email>' => '<some sender>'))
    ->setTo(array('<to email>' => '<some recepient>'))
    ->setBody($htmlbody, 'text/html');

// Send the message
$result = $mailer->send($message);

var_dump($result);
?>

谢谢!

推荐答案

这是一个旧线程,但是对于相同的错误,我的解决方案有点不同.原来我的 Swift 配置很好.我的服务器的 IP 被谷歌阻止为可疑.我可以通过访问此链接来清除它,然后从服务器执行我的邮件程序代码.

This is an old thread, but my resolution was a bit different for the same error. Turns out my Swift configuration is fine. The IP from my server was blocked by Google as suspicious. I was able to clear it by visiting this link, then executing my mailer code from the server.

http://www.google.com/accounts/DisplayUnlockCaptcha

这篇关于PHP 致命错误:“Swift_TransportException"和消息“无法在 SMTP 服务器上进行身份验证"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:PHP 致命错误:“Swift_TransportException"和消息“无法在 SMTP 服务器上进行身份验证"

基础教程推荐