Lemme prefix, this question by saying that I've been searching around for 3 days new gmail's data that can be used to send mails.
So when building Swift's transport, I'm providing this
Swift_SmtpTransport::newInstance('smtp.gmail.com', 465, 'tls')
And also, instead of 465, providing 587 with no luck. The error is its like it starts to run an endless loop and then the script execution halts.
The data (username/password) is 100% correct and it has been tested in isolation. (with dummy test.php
witn included Swift library), if that helps.
To be specific:
<?php
// File:test.php
require(__DIR__ . '/vendor/SwiftMailer/swift_required.php');
$email = 'my-username@gmail.com';
$pass = 'my-password';
$html = '<p>Foo bar</p>';
// Build a transport
$transport = Swift_SmtpTransport::newInstance('smtp.gmail.com', 587, 'tls')
->setUsername($email)
->setPassword($pass);
$mailer = Swift_Mailer::newInstance($transport);
$message = Swift_Message::newInstance('New email')
->setFrom(array($email => 'Test app'))
->setTo(array($email))
->setBody($html, 'text/html');
$mailer->send($message);
it throws:
Uncaught exception 'Swift_TransportException' with message 'Unable to connect with TLS encryption'
And when using:
$transport = Swift_SmtpTransport::newInstance('smtp.gmail.com', 465, 'ssl')
It ends up with endless loop.
Tired of searching in Google for this gmail's issue. Maybe anyone has faced this and has a solution already?