使用php,gmail和swiftmailer发送电子邮件会导致与SSL相关的错误 [英] Sending email using php, gmail, and swiftmailer causes SSL-related error

查看:349
本文介绍了使用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);
    */ 
}

这是错误:

(!)警告:fsockopen()[function.fsockopen]:无法连接到ssl://smtp.gmail.com:465(无法找到套接字传输ssl - 您是否忘记在配置PHP时启用它?)在C:\Program Files\wamp\www\swift-mailer\lib\classes\Swift\Transport\ StreamBuffer.php在线233

(!)致命错误:未捕获的异常Swift_TransportException与消息'连接可能没有建立与主机smtp.gmail.com [无法找到套接字传输ssl - 您忘记启用它,当您配置PHP? #44551400]'in C:\Program Files\wamp\www\swift-mailer\lib\classes\Swift\Transport\StreamBuffer.php on line 235

(!)Swift_TransportException:无法与主机smtp.gmail.com建立连接[无法找到套接字传输ssl - 是吗配置PHP时忘记启用它? #44551400] in C:\Program Files\wamp\www\swift-mailer\lib\classes\Swift\Transport\StreamBuffer.php在第235行

问题在哪里?

我检查了 phpinfo(),它说:

OpenSSL support     disabled (install ext/openssl) 

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

I referred to the links below, but I couldn't install ssl...

推荐答案

您的php是否支持SSL? http://php.net/manual/en/function.fsockopen.php ,并检查 http://www.php.net/manual/en/openssl。 install.php 供参考。

Did your php support SSL ? http://php.net/manual/en/function.fsockopen.php, and check http://www.php.net/manual/en/openssl.installation.php for reference.

使用

phpinfo();

是否启用SSL?

这篇关于使用php,gmail和swiftmailer发送电子邮件会导致与SSL相关的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆