刚刚将我的 swiftmailer 结帐更新到最新版本 4.3.0。以下非常简单的代码不再起作用,并且连接超时:
<?
require_once 'Swift-4.3.0/lib/swift_required.php';
$transport = Swift_SmtpTransport::newInstance('email-smtp.us-east-1.amazonaws.com',465, 'tls')
->setUsername('USERNAME')
->setPassword('PASSWORD')
;
$mailer = Swift_Mailer::newInstance($transport);
// Create a message
$message = Swift_Message::newInstance('Yo')
->setFrom(array('jnankin@gmail.com' => 'Josh'))
->setTo(array('jnankin@gmail.com'))
->setBody('Here is the message itself')
;
$result = $mailer->send($message);
然后我得到以下信息:
PHP Fatal error: Uncaught exception 'Swift_IoException' with message 'Connection to tcp://email-smtp.us-east-1.amazonaws.com:465 Timed Out' in /home/jnankin/Desktop/Swift-4.3.0/lib/classes/Swift/Transport/StreamBuffer.php:169
Stack trace:
#0 /home/jnankin/Desktop/Swift-4.3.0/lib/classes/Swift/Transport/AbstractSmtpTransport.php(400): Swift_Transport_StreamBuffer->readLine(0)
#1 /home/jnankin/Desktop/Swift-4.3.0/lib/classes/Swift/Transport/AbstractSmtpTransport.php(291): Swift_Transport_AbstractSmtpTransport->_getFullResponse(0)
#2 /home/jnankin/Desktop/Swift-4.3.0/lib/classes/Swift/Transport/AbstractSmtpTransport.php(119): Swift_Transport_AbstractSmtpTransport->_readGreeting()
#3 /home/jnankin/Desktop/Swift-4.3.0/lib/classes/Swift/Mailer.php(80): Swift_Transport_AbstractSmtpTransport->start()
#4 /home/jnankin/Desktop/email.php(17): Swift_Mailer->send(Object(Swift_Message))
#5 {main}
thrown in /home/jnankin/Desktop/Swift-4.3.0/lib/classes/Swift/Transport/StreamBuffer.php on line 169
更新:这个完全相同的代码(没有任何更改)在版本 4.1.2 中有效。版本 4.1.3 这不再有效。我尝试过不同的 SMTP 服务器:mailgun、sendgrid 等……这似乎是 swiftmailer 特有的。