$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