$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);
网页浏览器返回错误:
致命错误:未捕获的异常 'Swift_TransportException' 带有消息 '无法与主机 smtp.gmail.com 建立连接 [无法找到套接字传输“ssl” - 您在配置 PHP 时是否忘记启用它?#157919304]' 在 C:\Program Files\xampp\htdocs\healthcare system\swift\lib\classes\Swift\Transport\StreamBuffer.php:259 堆栈跟踪:#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->