$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);
网页上的错误: Web浏览器返回错误:
致命错误:未捕获异常'Swift_TransportException',消息'无法与主机smtp一起建立连接[无法找到套接字传输“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-> start ()#3 C:\ Program Files \ xampp \ htdocs \ healthcare system \ mail_process.php(32):Swift_Mailer-> send(Object(Swift_Message))#4 {main}抛出C:\ Program Files \ xampp \第259行的htdocs \ healthcare system \ swift \ lib \ classes \ Swift \ Transport \ StreamBuffer.php
答案 0 :(得分:0)
错误非常明显,您需要启用PHP的套接字扩展以使用SSL(Gmail使用此类连接)。
你正在使用XAMPP吗?看看这个:Enabling SSL with XAMPP
Swiftmailer适用于Gmail,相信我。
启用后,验证您的Swiftmail配置:
parameters:
mailer_transport: gmail
mailer_host: ~
mailer_user: some@email.com
mailer_password: somepassword
答案 1 :(得分:0)
我正在广泛搜索这个问题的答案,事实证明我必须使用PHP 5.5
来实现这个目标。当我遇到同样的问题时,我正在使用5.6(可能是5.6.15)。如果你使用PHP 5.5
,你可能想看看它是否适用于较新版本的PHP ......