使用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 ...     
已邀请:
你的php支持SSL吗? http://php.net/manual/en/function.fsockopen.php,并查看http://www.php.net/manual/en/openssl.installation.php以供参考。 用。创建一个页面
phpinfo();
是否启用了SSL?     
我正在寻找类似的问题,我发现你必须编辑php.ini文件 编辑以下行
;extension=php_openssl.dll
删除半结肠,它会正常工作 希望能帮助其他任何人:)     
gmail在你的config.yml中需要这个 swiftmailer:     加密:tls 或者替换你的: - > setEncryption( 'SSL') 通过 - > setEncryption( 'TLS') 而不是ssl     
你应该从php扩展启用php_openssl模块。只需编辑您的php.ini文件
extension=php_openssl.dll
    
事实上,我建议在端口25上使用tls 使用以下语法进行测试:
$transport = Swift_SmtpTransport::newInstance('smtp.gmail.com', 25, 'tls')
    ->setUsername('007@gmail.com')
    ->setPassword('123');
    
您需要配置php以使用ssl http://www.php.net/manual/en/openssl.installation.php     
我希望你已经解决了你的问题,但对我而言:
;extension=php_openssl.dll
在我的php.ini中不存在(在Win7上运行XAMPP 1.7.7), 所以,继续将其添加到扩展部分,从中删除分号,它应该工作。     

要回复问题请先登录注册