0
votes
  $transport = Swift_SmtpTransport::newInstance('smtp.gmail.com', 465, "ssl")

 ->setUsername('username')
 ->setPassword('password');

 $username = $_SESSION['username'];  
 $from = $_POST['from'];
 $to =  $_POST['to'];
 $subject = $_POST['subject'];
 $body = $_POST['message'];

 $message = Swift_Message::newInstance($subject)

->setFrom(array($from => $username))
->setTo(array($to))
->setBody($body);

$mailer = Swift_Mailer::newInstance($transport);
$result = $mailer->send($message);

Error on Webpage : Error returned on web browser:

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? #157919304]' in C:\Program Files\xampp\htdocs\healthcare system\swift\lib\classes\Swift\Transport\StreamBuffer.php:259 Stack trace: #0 C:\Program Files\xampp\htdocs\healthcare system\swift\lib\classes\Swift\Transport\StreamBuffer.php(64): Swift_Transport_StreamBuffer->_establishSocketConnection() #1 C:\Program Files\xampp\htdocs\healthcare system\swift\lib\classes\Swift\Transport\AbstractSmtpTransport.php(115): Swift_Transport_StreamBuffer->initialize(Array) #2 C:\Program Files\xampp\htdocs\healthcare system\swift\lib\classes\Swift\Mailer.php(80): Swift_Transport_AbstractSmtpTransport->start() #3 C:\Program Files\xampp\htdocs\healthcare system\mail_process.php(32): Swift_Mailer->send(Object(Swift_Message)) #4 {main} thrown in C:\Program Files\xampp\htdocs\healthcare system\swift\lib\classes\Swift\Transport\StreamBuffer.php on line 259

2
This is the common error that I have been facing when I use swift mailer and I don't know what else is left to be configured.. I am new to using Swift Mailer but any other method to use GMail to send does not seem to be working. Please Help. Thanks alot in advance.Darsshan Nair
Did you find my answer useful?coma

2 Answers

0
votes

The error is very clear, you need to enable the socket extension for PHP to use SSL (Gmail uses this kind of connection).

You are using XAMPP right? check this out: Enabling SSL with XAMPP

Swiftmailer works great with Gmail, trust me.

After enabling it, verify your Swiftmail config:

parameters:
    mailer_transport:  gmail
    mailer_host:       ~
    mailer_user:       [email protected]
    mailer_password:   somepassword
0
votes

I was searching far and wide for an answer to this issue, and it turned out that I had to use PHP 5.5 to get this working. I was using 5.6 (probably 5.6.15) when I had the same issue. If you get it working with PHP 5.5 you might want to see if it works with newer versions of PHP...