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 :
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