问题描述
我已经在google中搜索过它,并尝试了中的所有建议,但仍然收到致命错误:
我使用 SwiftMailer
发送和电子邮件到 GMAIL 。它在我的本地主机上完美工作,但是当我上传并尝试时,它给了我一个致命错误:
以下是我的代码的一部分:
require_once'Swift-5.1.0 / lib / swift_required.php';
$ email [email protected];
$ transport = Swift_SmtpTransport :: newInstance('ssl://smtp.gmail.com',465);
$ transport-> setUsername([email protected]);
$ transport-> setPassword(usernamepassword);
//创建消息
$ message = Swift_Message :: newInstance();
$ message-> setTo(array(
[email protected]=>First Name
));
$ message-> setCc(array([email protected]=>Name NAme,[email protected]=>他的名字));
$ message-> setSubject(Subject);
$ message-> setBody(The Body);
$ message-> setFrom($ email,Full Name);
$ message-> setReplyTo(array($ email =>Full Name));
//发送邮件
$ mailer = Swift_Mailer :: newInstance($ transport);
$ mailer-> send($ message);
这是我发送电子邮件至Gmail时发生的致命错误:
$ b
我不确定,但我想当你添加端口465时,Swift类会自动添加ssl协议。
尝试
$ transport = Swift_SmtpTransport :: newInstance('smtp.gmail.com',465);
I had already searched it in google and tried all the suggestions here in StackOverflow but I still get a Fatal Error:
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 = "[email protected]";
$transport = Swift_SmtpTransport::newInstance('ssl://smtp.gmail.com', 465);
$transport->setUsername("[email protected]");
$transport->setPassword("usernamepassword");
// Create the message
$message = Swift_Message::newInstance();
$message->setTo(array(
"[email protected]" => "First Name"
));
$message->setCc(array("[email protected]" => "Name NAme" , "[email protected]" => "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);
This is the Fatal Error I get when I send an email to gmail :
I'm not sure but I think when you adding port 465, Swift class automatically will add ssl protocol.
Try
$transport = Swift_SmtpTransport::newInstance('smtp.gmail.com', 465);
这篇关于没有捕获异常'Swift_TransportException',并显示消息'连接无法与主机smtp.gmail.com建立连接[连接超时#110]'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!