I know there's some questions on this but my problem isn't solved by any of the ones I could find.
I'm using swift mailer 4.2.1 on LAMP.
I have openSSL enabled:
So I tried SSL connection with the following code:
$transporter = Swift_SmtpTransport::newInstance('smtp.gmail.com', 465, 'ssl')
->setUsername('[email protected]')
->setPassword("pwd");
$mailer = Swift_Mailer::newInstance($transporter);
$message = Swift_Message::newInstance($subject)
->setFrom(array($from => 'From name'))
->setTo(array($to=> $name))
->setBody($html_content);
$result = $mailer->send($message);
This throws me the following error
Uncaught exception 'Swift_TransportException' with message 'Failed to authenticate on SMTP server with username "[email protected]" using 2 possible authenticators' in /Swift/lib/classes/Swift/Transport/Esmtp/AuthHandler.php:171
If I change the code to use tls like:
$transporter = Swift_SmtpTransport::newInstance('smtp.gmail.com', 587, 'tls')...(rest is the same)
I get the same error. And I get a connection timeout if I try to use port 465 with tls.
If I run:
$sock = fsockopen('tls://smtp.gmail.com', 465, $errno, $errstr, 10);
echo 'Socket is: ';
var_dump($sock);
echo 'Errors: ' . $errno . ' ' . $errstr;
I get
Socket is: resource(2) of type (stream) Errors: 0
Additional info:
var_dump(stream_get_transports());
returns:
array(8) { [0]=> string(3) "tcp" 1=> string(3) "udp" [2]=> string(4) "unix" [3]=> string(3) "udg" [4]=> string(3) "ssl" [5]=> string(5) "sslv3" [6]=> string(5) "sslv2" [7]=> string(3) "tls" }
So I have both ssl and tls wrappers...
Swift_Transport_Esmtp_AuthHandler
you havegetAuthenticators()
and_getAuthenticatorsForAgent()
. Go into code, and find out if SwiftMailer is actually supporting the auth methods required by the server. Once again, this does not sound a like a SSL problem, I don't know why you keep debugging in that direction. – Tiberiu-Ionuț Stan