9

这是我的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 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) 

我参考了下面的链接,但我无法安装 ssl ...

4

7 回答 7

16

我正在寻找类似的问题,我发现您必须编辑 php.ini 文件编辑以下行

;extension=php_openssl.dll

删除半冒号,它会正常工作

希望对其他人有所帮助:)

于 2011-12-17T09:00:45.207 回答
3

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

创建一个页面

phpinfo();

是否启用 SSL?

于 2011-01-31T00:29:54.453 回答
2

gmail 在你的 config.yml 中需要这个

swiftmailer:加密:tls

或替换您的: ->setEncryption('ssl') 为 ->setEncryption('tls')

而不是ssl

于 2013-01-06T16:45:12.637 回答
1

您应该从 php 扩展中启用 php_openssl 模块。只需编辑您的php.ini文件

extension=php_openssl.dll
于 2013-01-05T17:57:23.633 回答
1

事实上,我建议使用以下语法在端口 25 上使用 tls 测试:

$transport = Swift_SmtpTransport::newInstance('smtp.gmail.com', 25, 'tls')
    ->setUsername('007@gmail.com')
    ->setPassword('123');
于 2013-10-22T13:54:26.250 回答
0

您需要配置 php 以使用 ssl

http://www.php.net/manual/en/openssl.installation.php

于 2011-01-31T00:43:05.550 回答
0

我希望你已经解决了你的问题,但是对我来说:

;extension=php_openssl.dll

在我的 php.ini 中不存在(在 Win7 上运行 XAMPP 1.7.7),所以继续将它添加到扩展部分,从中删除分号,它应该可以工作。

于 2012-06-02T19:14:19.950 回答