Uncaught exception #39;Swift_TransportException#39; with message #39;Connection could not be established with host smtp.gmail.com [Connection timed out #110]#39;(未捕获的异常“Swift_TransportException和消息“无法与主机 smtp.gmail.com 建立连接 [连接超时 #110]) - IT屋-程序员软件开发技术分享
问题描述
我已经在 google 中搜索过它并在 StackOverflow 中尝试了所有建议,但我仍然收到 致命错误:
I had already searched it in google and tried all the suggestions here in StackOverflow but I still get a Fatal Error:
我使用 SwiftMailer
发送和 email 到 GMAIL.它在我的本地主机上完美运行,但是当我上传它并尝试时它给了我一个 致命错误:
I am using SwiftMailer
for sending and email to GMAIL. It works perfectly on my localhost but when I uploaded it and try It gives me a Fatal Error:
这是我的代码的一部分:
Here is a part of my code:
require_once 'Swift-5.1.0/lib/swift_required.php';
$email = "fromemail@gmail.com";
$transport = Swift_SmtpTransport::newInstance('ssl://smtp.gmail.com', 465);
$transport->setUsername("username@gmail.com");
$transport->setPassword("usernamepassword");
// Create the message
$message = Swift_Message::newInstance();
$message->setTo(array(
"to@gmail.com" => "First Name"
));
$message->setCc(array("cc_email1@gmail.com" => "Name NAme" , "cc_email2@gmail.com" => "His Name"));
$message->setSubject("Subject");
$message->setBody("The Body");
$message->setFrom($email, "Full Name");
$message->setReplyTo(array($email => "Full Name"));
// Send the email
$mailer = Swift_Mailer::newInstance($transport);
$mailer->send($message);
这是我向 gmail 发送电子邮件时遇到的致命错误:
致命错误:在/homepages/41/d513702051/htdocs/php/Swift-5.1 中未捕获异常Swift_TransportException",并带有消息无法与主机 smtp.gmail.com [连接超时 #110] 建立连接".0/lib/classes/Swift/Transport/StreamBuffer.php:266 堆栈跟踪:#0/homepages/41/d513702051/htdocs/php/Swift-5.1.0/lib/classes/Swift/Transport/StreamBuffer.php(64): Swift_Transport_StreamBuffer->_establishSocketConnection() #1/homepages/41/d513702051/htdocs/php/Swift-5.1.0/lib/classes/Swift/Transport/AbstractSmtpTransport.php(115): Swift_Transport_StreamBuffer->initialize(Array) #2/homepages/41/d513702051/htdocs/php/Swift-5.1.0/lib/classes/Swift/Mailer.php(80): Swift_Transport_AbstractSmtpTransport->start() #3/homepages/41/d513702051/htdocs/php/contactus.php(33): Swift_Mailer->send(Object(Swift_Message)) #4 {main} 抛出/homepages/41/d513702051/htdocs/php/Swift-5.1.0/lib/classes/Swift/Transport/StreamBuffer.php 在第 266 行
Fatal error: Uncaught exception 'Swift_TransportException' with message 'Connection could not be established with host smtp.gmail.com [Connection timed out #110]' in /homepages/41/d513702051/htdocs/php/Swift-5.1.0/lib/classes/Swift/Transport/StreamBuffer.php:266 Stack trace: #0 /homepages/41/d513702051/htdocs/php/Swift-5.1.0/lib/classes/Swift/Transport/StreamBuffer.php(64): Swift_Transport_StreamBuffer->_establishSocketConnection() #1 /homepages/41/d513702051/htdocs/php/Swift-5.1.0/lib/classes/Swift/Transport/AbstractSmtpTransport.php(115): Swift_Transport_StreamBuffer->initialize(Array) #2 /homepages/41/d513702051/htdocs/php/Swift-5.1.0/lib/classes/Swift/Mailer.php(80): Swift_Transport_AbstractSmtpTransport->start() #3 /homepages/41/d513702051/htdocs/php/contactus.php(33): Swift_Mailer->send(Object(Swift_Message)) #4 {main} thrown in /homepages/41/d513702051/htdocs/php/Swift-5.1.0/lib/classes/Swift/Transport/StreamBuffer.php on line 266
推荐答案
我不确定,但我认为当你添加端口 465 时,Swift 类会自动添加 ssl 协议.
I'm not sure but I think when you adding port 465, Swift class automatically will add ssl protocol.
试试
$transport = Swift_SmtpTransport::newInstance('smtp.gmail.com', 465);
这篇关于未捕获的异常“Swift_TransportException"和消息“无法与主机 smtp.gmail.com 建立连接 [连接超时 #110]"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:未捕获的异常“Swift_TransportException"和消息“无法与主机 smtp.gmail.com 建立连接 [连接超时 #110]"
基础教程推荐
- WooCommerce 中选定产品类别的自定义产品价格后缀 2021-01-01
- XAMPP 服务器不加载 CSS 文件 2022-01-01
- 通过 PHP SoapClient 请求发送原始 XML 2021-01-01
- 在 Woocommerce 中根据运输方式和付款方式添加费用 2021-01-01
- Libpuzzle 索引数百万张图片? 2022-01-01
- 如何在 PHP 中的请求之间持久化对象 2022-01-01
- 在 PHP 中强制下载文件 - 在 Joomla 框架内 2022-01-01
- 超薄框架REST服务两次获得输出 2022-01-01
- mysqli_insert_id 是否有可能在高流量应用程序中返回 2021-01-01
- 在多维数组中查找最大值 2021-01-01