1
votes

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: enter image description here

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

2
"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" this doesn't sound like a SSL problem.Tiberiu-Ionuț Stan
Great. Not much help but thanksjribeiro
First find out if Swift Mailer supports the auth methods allowed by the server. Check if the sent password is incorrect (if you hardcoded the password, make sure you escaped it properly, "imakelotsof\$daily"). On an object of type Swift_Transport_Esmtp_AuthHandler you have getAuthenticators() 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

2 Answers

2
votes

I think you can use this :

$transport = Swift_SmtpTransport::newInstance('smtp.googlemail.com', 465, "ssl") 
     ->setUsername('[email protected]') 
     ->setPassword('test'); 

-->smtp with googlemail instead of gmail..

0
votes

The password you use should be the one generated from your 'Application Specific password' and not your original password.