0

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?

Community
  • 1
  • 1
Yang
  • 8,580
  • 8
  • 33
  • 58
  • try opening an issue at github https://github.com/swiftmailer/swiftmailer/issues – Saqueib Feb 09 '15 at 09:14
  • 465 is using ssl, while 587 is using tls. (took only a few seconds to find the relevant documentation of google: https://support.google.com/a/answer/176600?hl=en). From the Swift docs: For SSL or TLS encryption to work your PHP installation must have appropriate OpenSSL transports wrappers. You can check if "tls" and/or "ssl" are present in your PHP installation by using the PHP function stream_get_transports() – Markus Müller Feb 09 '15 at 09:21
  • @Markus no, I already mentioned, by saying that tired of searching for this issue, and that I already encountered recommendations like yours. My problem is that it used to work in the past, but now it no longer works. And yeah, I'm well aware that it needs tls or ssl, so yes they are loaded – Yang Feb 09 '15 at 09:38
  • @Saqueib I believe that's not Swift Email issue itself because it works well with another providers, but gmail. And it used to work in the past – Yang Feb 09 '15 at 09:39
  • Ah you updated your question. Much better now. – Markus Müller Feb 09 '15 at 09:39
  • @bad_boy ya maybe, you should change the question title also – Saqueib Feb 09 '15 at 09:40
  • @Saqueib I think the title states my question clearly: *It used to work in the past, but now it no longer works with gmail* – Yang Feb 09 '15 at 09:42
  • Are you able to record the raw tcp packets? You might be able to gain more insights to the failure reason. I'm not sure which logging framework is used by swift. But activating debug logging within swift might also help – Markus Müller Feb 09 '15 at 09:44
  • @Markus After quick browsing its code, Swift doesn't seem to use any logging mechanism. It simply throws exceptions, but learning the whole source code and understand how it works under the hood is the last thing I would want to do, because it will take a loot of time. – Yang Feb 09 '15 at 10:32
  • mhh that's odd. I suggest you do what @Saqueib suggested and post an issue over at github – Markus Müller Feb 09 '15 at 13:21

1 Answers1

0

Have you check SSL enable on your PHP yet?

extension=php_openssl.dll in PHP.ini ?

Or check to your network admin relate with send email access port problem?

koe
  • 736
  • 1
  • 12
  • 33
  • @bad_boy sorry i missing see your command, I used to meet problem with send email, i do it well at my home but it's send email fail when i go to demo my teacher bcoz internet school close send email port access, so you can try your code with other internet connect – koe Feb 09 '15 at 10:23