laravel 5.5无法使用gmail发送电子邮件

时间:2018-03-15 15:42:24

标签: laravel

Windows 10,Apache httpd 2.4,PHP 7.1.4,Laravel 5.5
Gmail的安全性较低是允许的。

我的.env文件:

MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=465
MAIL_USERNAME=account@gmail.com
MAIL_PASSWORD=password
MAIL_ENCRYPTION=ssl

错误讯息:
无法与主机smtp.gmail.com

建立连接
MAIL_PORT=587
MAIL_ENCRYPTION=tls

错误讯息:
stream_socket_enable_crypto():SSL操作失败,代码为1. OpenSSL错误消息:\ n
错误:14090086:SSL例程:ssl3_get_server_certificate:证书验证失败

我也试过

MAIL_DRIVER=sendmail 

错误讯息:
无法启动流程

有人说我的问题与这个问题重复:
laravel : cURL error 60: SSL certificate unable to get local issuer certificate

但是那个问题,没有接受答案,所有答案都不起作用。 我添加了一个回复,说出我遇到的问题,然后有人说答案应该是答案,我的答复不是答案。我应该问一个新问题。在那个问题上,我的回复被删除了!

以下是我的所作所为:( Webinion的回答)
把cacert.pem

/vendor/guzzlehttp/guzzle/src/cacert.pem  

编辑Client.php

/vendor/guzzlehttp/guzzle/src/Client.php

private function configureDefaults(array $config)
{
    echo "<pre>", print_r(123, 1), "</pre>"; exit;

    $defaults = [
        'allow_redirects' => RedirectMiddleware::$defaultSettings,
        'http_errors'     => true,
        'decode_content'  => true,
        //'verify'          => true,
        'verify'          => dirname(__FILE__).'/cacert.pem',
        'cookies'         => false
    ];

起初,我添加了cacert.pem行,没有工作 然后我添加了回声线,没有看到123并且它没有退出。 看来这个Client.php没用过?

错误讯息:

Swift_TransportException   
Connection could not be established with host smtp.gmail.com [ #0]

D:\www\...\vendor\swiftmailer\swiftmailer\lib\classes\Swift\Transport\StreamBuffer.php

if (false === $this->stream) {
    throw new Swift_TransportException(
        'Connection could not be established with host '.$this->params['host'].
        ' ['.$errstr.' #'.$errno.']'
        );
}

答案说guzzlehttp,但我的错误信息是swiftmailer。 Laravel现在使用不同的包装?

1 个答案:

答案 0 :(得分:0)

我找到了解决方案。无需更改另一个问题中建议的guzzlehttp / guzzle / src / Client.php。

解决方案:

  1. https://curl.haxx.se/docs/caextract.html下载cacert.pem文件 把cacert.pem放在你喜欢的地方。

  2. 编辑php.ini

  3. 两行:

    curl.cainfo=D:/Servers/php/sslfiles/cacert.pem  
    openssl.cafile=D:/Servers/php/sslfiles/cacert.pem 
    
    1. 重启apache httpd。