laravel 5.5无法使用gmail发送电子邮件 [英] laravel 5.5 cannot send emails using gmail

查看:73
本文介绍了laravel 5.5无法使用gmail发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Windows 10, Apache httpd 2.4, PHP 7.1.4, Laravel 5.5
Gmail's less secure is Allowed.

我的.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建立连接

Error Message:
Connection could not be established with host smtp.gmail.com

MAIL_PORT=587
MAIL_ENCRYPTION=tls

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

Error Message:
stream_socket_enable_crypto(): SSL operation failed with code 1. OpenSSL Error messages:\n
error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed

我也尝试过

MAIL_DRIVER=sendmail 

错误消息:
进程无法启动

Error Message:
Process could not be started

有人说我的问题是这个问题的重复:
laravel:cURL错误60:SSL证书无法获得本地发行者证书

Some people say that my question is duplicate of this question:
laravel : cURL error 60: SSL certificate unable to get local issuer certificate

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

But that question, no answer is accepted, and all the answers don't work. I added a reply, say the problem I encoutered, then someone says that a reply should be an answer, my reply is not an answer. I should ask a new question. In that question, my reply was deleted!

这是我的工作:(Webinion的回答)
放入cacert.pem

Here is what I did: (Webinion's answer)
Put cacert.pem

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

编辑Client.php

Edit 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没有被使用?

At first, I added the cacert.pem line, not working.
Then I added the echo line, didn't see 123 and it didn't exit. It seems that this Client.php is not used?

错误消息:

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现在使用不同的软件包吗?

That answer says guzzlehttp but my error message says swiftmailer. Laravel now uses different packages?

推荐答案

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

I found the solution. No need to change guzzlehttp/guzzle/src/Client.php which is suggested in another question.

解决方案:

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

  1. Download cacert.pem file from https://curl.haxx.se/docs/caextract.html
    Put the cacert.pem somewhere you like.

编辑php.ini

两行:

curl.cainfo=D:/Servers/php/sslfiles/cacert.pem  
openssl.cafile=D:/Servers/php/sslfiles/cacert.pem 

  1. 重新启动apache httpd.

这篇关于laravel 5.5无法使用gmail发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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