使用php,gmail和swiftmailer发送电子邮件会导致与SSL相关的错误
这是我的PHP代码:
function SendCookieToTheMail()
{
require_once 'swift-mailer/lib/swift_required.php';
//Create the Transport
$transport = Swift_SmtpTransport::newInstance('smtp.gmail.com')
->setPort(465)
->setEncryption('ssl')
->setUsername('007@gmail.com')
->setPassword('123')
;
//Create the Mailer using your created Transport
$mailer = Swift_Mailer::newInstance($transport);
//Create a message
$message = Swift_Message::newInstance('Test')
->setFrom(array('007@gmail.com' => 'From mr. 007'))
->setTo(array('007@gmail.com', '007@gmail.com' => 'To mr. 007'))
->setBody('Body')
;
//Send the message
$result = $mailer->send($message);
/*
You can alternatively use batchSend() to send the message
$result = $mailer->batchSend($message);
*/
}
这是错误:
( ! ) Warning: fsockopen() [function.fsockopen]: unable to connect to ssl://smtp.gmail.com:465 (Unable to find the socket transport "ssl" - did you forget to enable it when you configured PHP?) in C:Program Fileswampwwwswift-mailerlibclassesSwiftTransportStreamBuffer.php on line 233
( ! ) 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? #44551400]' in C:Program Fileswampwwwswift-mailerlibclassesSwiftTransportStreamBuffer.php on line 235
( ! ) Swift_TransportException: 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? #44551400] in C:Program Fileswampwwwswift-mailerlibclassesSwiftTransportStreamBuffer.php on line 235
问题出在哪儿??
更新:
我检查了phpinfo()
,它说:
OpenSSL support disabled (install ext/openssl)
我提到了下面的链接,但我无法安装ssl ...
没有找到相关结果
已邀请:
7 个回复
梦话快家腹
是否启用了SSL?
蜂佬渺
删除半结肠,它会正常工作 希望能帮助其他任何人:)
膝垫富顷
纫合峭
碧肮械淌设
鞋扣蚊冈借
凄嘛姥
在我的php.ini中不存在(在Win7上运行XAMPP 1.7.7), 所以,继续将其添加到扩展部分,从中删除分号,它应该工作。