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('mymail@gmail.com')
->setPassword('password');
$mailer = Swift_Mailer::newInstance($transport);
$message = Swift_Message::newInstance()
->setSubject('Localhost email test')
->setFrom(array('mymail@gmail.com' => 'test'))
->setTo(array('testmail@hotmail.com' => '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!