windows - 在 Laravel 5 中发送电子邮件不起作用

标签 windows laravel email ssl laravel-5

在论坛中搜索了很长时间后,我找不到对我的案例有用的解决方案。
我在 laravel 中做了很多发送电子邮件的功能,并且总是工作正常。
这一次,我收到了一个错误,如下所示:

ErrorException in StreamBuffer.php line 95:
stream_socket_enable_crypto(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed

这是我的 .env 文件

APP_ENV=local
APP_DEBUG=true
APP_KEY=base64:FMtA/k/okcPZB/HbWGbw5YiBM4EC3njxxLbgcdM1GrA=
APP_URL=http://localhost

DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=myDB
DB_USERNAME=root
DB_PASSWORD=

CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=suckerblood2010@gmail.com
MAIL_PASSWORD=<<Here_my_password>>
MAIL_ENCRYPTION=tls

MAIL_SENDER=Administration

这里是我发送邮件的函数(在 Controller Auth 中):

public function register(Request $request)
{
    $this->validateLogin($request);

    $token = hash('sha256', str_random(100) . time(), false);
    $user = new User();
    $user->email = $request->get('email');
    $user->password = bcrypt($request->get('password'));
    $user->remember_token = $token;
    //$user->save();

    $sent = Mail::send('auth.emails.createAccount', ['token' => $token], function ($m) use ($user) {
        $m->from(getenv('MAIL_USERNAME'), getenv('MAIL_SENDER'));

        $m->to($user->email, $user->email)->subject(config('constants.AccountCreated'));
    });

    if($sent == 1)
    {
        $msg = Lang::get('messages.EmailSent');
        $this->showLoginForm($msg);
    }
    else
    {
        return redirect('/login')->withErrors([
            'email' => Lang::get('messages.UserAddingError')
        ]);
    }
}

我尝试将协议(protocol)从 tls 更改为 ssl,甚至将 prot 从 587 更改为 465
我只在这个项目中遇到这个问题,尽管我进行了所有搜索,但我不明白为什么……

有什么建议吗?
非常感谢:)

最佳答案

您的根证书丢失或损坏,请尝试安装一个

# 1) Download a valid root ca
http://curl.haxx.se/ca/cacert.pem

# 2) Setup php.ini to point it
openssl.cafile=C:\php5\etc\cacert.pem

要确保它们已加载,请查看此控制台命令响应

php -r 'var_dump(openssl_get_cert_locations());

您可能需要重新启动您的网络服务器


您也可以在 php.ini 中禁用 ssl 对等验证,但不推荐这样做(请不要在生产环境中这样做!)

openssl.verify_peer 0

有用的文档:http://php.net/manual/migration56.openssl.php

关于windows - 在 Laravel 5 中发送电子邮件不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40244658/

相关文章:

windows - 并行执行shell进程

mysql - 在后端阻止连续的 SQL 请求

php - Laravel如何使用查询生成器返回单列值

javascript - 如何在 laravel 中使用 jquery 从数据库中获取特定行并将其绑定(bind)到文本框字段

email - Drupal 7 的 Gmail smtp 配置

c# - 发送电子邮件时如何修复 'No connection could be made because the target machine actively refused it' 错误

c++ - IIS 7 启动时 glfwInit 失败

c++ - 如何创建一个新线程并在一段时间后终止它?

email - Lucee:如何以编程方式检查电子邮件是否卡在失败任务列表中

R 读取一个巨大的 csv