使用php,gmail和swiftmailer发送电子邮件会导致与SSL相关的错误

Los*_*ord 9 php email ssl gmail swiftmailer

这是我的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);
    */ 
}
Run Code Online (Sandbox Code Playgroud)

这是错误:

( ! ) 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 Files\wamp\www\swift-mailer\lib\classes\Swift\Transport\StreamBuffer.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 Files\wamp\www\swift-mailer\lib\classes\Swift\Transport\StreamBuffer.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 Files\wamp\www\swift-mailer\lib\classes\Swift\Transport\StreamBuffer.php on line 235

问题出在哪儿??

更新:

我检查了一下phpinfo(),它说:

OpenSSL support     disabled (install ext/openssl) 
Run Code Online (Sandbox Code Playgroud)

我提到了下面的链接,但我无法安装ssl ...

oso*_*sos 16

我正在搜索类似的问题,我发现你必须编辑php.ini文件编辑以下行

;extension=php_openssl.dll
Run Code Online (Sandbox Code Playgroud)

删除半结肠,它会正常工作

希望能帮助其他任何人:)


kea*_*tch 3

你的php支持SSL吗?http://php.net/manual/en/function.fsockopen.php,并检查http://www.php.net/manual/en/openssl.installation.php以供参考。

创建一个页面

phpinfo();
Run Code Online (Sandbox Code Playgroud)

是否启用了 SSL?