【问题标题】:Sending email in laravel 5 not working在 laravel 5 中发送电子邮件不起作用
【发布时间】:2017-03-07 18:42:44
【问题描述】:

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

StreamBuffer.php 第 95 行中的 ErrorException:
stream_socket_enable_crypto():SSL 操作失败,代码为 1。OpenSSL 错误消息: 错误:14090086:SSL 例程:SSL3_GET_SERVER_CERTIFICATE:证书验证失败

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

这里是我发送邮件的函数(在控制器 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')
        ]);
    }
}

我尝试将协议从 tls 更改为 ssl,甚至将 prot 从 587 更改为 465
我只有这个项目才有这个问题,我不明白为什么,尽管我做了所有的搜索......

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

【问题讨论】:

    标签: windows laravel email ssl laravel-5


    【解决方案1】:

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

    # 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

    【讨论】:

    • 您可以尝试install them,但最好的办法是禁用对等验证
    • 我不能像你告诉我的那样禁用它,这在生产中不推荐......
    • 您在 Windows 10 上有生产服务器?
    • 我在网上试过,它工作正常,只是在本地我得到了问题.. 没关系,谢谢大家:)
    猜你喜欢
    • 1970-01-01
    • 2015-10-01
    • 2023-03-12
    • 2021-09-27
    • 2013-09-25
    • 2018-09-21
    • 1970-01-01
    • 2016-01-27
    • 1970-01-01
    相关资源
    最近更新 更多