''Connection could not be established with host smtp.gmail.com [Unable to find the socket transport "ssl"

I'm trying to send a message with SwiftMailer using localhost. However I keep getting the error:

560:tid 1472] [client ::1:65504] PHP Fatal error:  Uncaught exception 'Swift_TransportException' with message 'Connection could not be established with host smtp.gmail.com [Unable to find the socket transport "ssl" - did you forget to enable it when you configured PHP? #166044768]'

I've had a look around stackoverflow and it's related questions, and i have changed to port to 465 and 587, and went into the php.ini file and removed the semicolon ( ; ) from

extension=php_openssl.dll

However, when I try to run my code, I still get the above mentioned error.

My code:

require_once '../lib/swift_required.php';

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

$mailer = Swift_Mailer::newInstance($transport);
$message = Swift_Message::newInstance()
    ->setSubject('Localhost email test')
    ->setFrom(array('[email protected]' => 'test'))
    ->setTo(array('[email protected]' => 'receiver'))
    ->setBody('This is a test message');

if ($mailer->send($message)) {
    echo 'The message was sent successfully!';

} else {
    echo 'Error sending email message';
}

Would appreciate any help I can get. Thanks!



Solution 1:[1]

sending email in CodeIgniter through gmail

please also check if you have uncommented extension=php_openssl.dll in php.ini

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Community