php 本地主机和“stream_socket_enable_crypto():SSL 操作失败,代码为 1”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/44423096/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 02:59:09  来源:igfitidea点击:

localhost and "stream_socket_enable_crypto(): SSL operation failed with code 1"

phplaravelemaillaravel-5.2

提问by Saucyloco

I was sending emails using gmail and everything was working perfectly, but suddendly it stoped working. And it shows me this

我正在使用 gmail 发送电子邮件,一切正常,但突然停止工作。它向我展示了这个

ErrorException in StreamBuffer.php line 94:

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

in StreamBuffer.php line 94
at HandleExceptions->handleError('2', 'stream_socket_enable_crypto(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed', 'C:\xampp\htdocs\coparmex\vendor\swiftmailer\swiftmailer\lib\classes\Swift\Transport\StreamBuffer.php', '94', array())
at stream_socket_enable_crypto(resource, true, '9') in StreamBuffer.php line 94
at Swift_Transport_StreamBuffer->startTLS() in EsmtpTransport.php line 313
at Swift_Transport_EsmtpTransport->_doHeloCommand() in AbstractSmtpTransport.php line 118
at Swift_Transport_AbstractSmtpTransport->start() in Mailer.php line 79
at Swift_Mailer->send(object(Swift_Message), array()) in Mailer.php line 385
at Mailer->sendSwiftMessage(object(Swift_Message)) in Mailer.php line 171

And this only happends in my localhost, in the web host works fine. I don't understand what is going on :c

这仅发生在我的本地主机中,在网络主机中工作正常。我不明白发生了什么:c

These are my gmail settings

这些是我的 Gmail 设置

MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=gmail
MAIL_PASSWORD=password
MAIL_ENCRYPTION=tls

采纳答案by andreyrk

That's an error with your SSL certificate. You're trying to use a SSL connection (encrypted, secure connection) without a proper certificate.

这是您的 SSL 证书错误。您正在尝试使用没有正确证书的 SSL 连接(加密的、安全的连接)。

That's because you're connecting from localhost, which isn't secure, and that is blocked by the connection. You could avoid that by changing your localhost connection to a SSL based one.

那是因为您从 localhost 连接,这不安全,并且被连接阻止。您可以通过将 localhost 连接更改为基于 SSL 的连接来避免这种情况。

See this linkfor more details.

有关更多详细信息,请参阅此链接

回答by Junaid Masood

You should add below code in /config/mail.php ( worked on laravel 5.4 )

您应该在 /config/mail.php 中添加以下代码(在 laravel 5.4 上工作)

'stream' => [
'ssl' => [
    'allow_self_signed' => true,
    'verify_peer' => false,
    'verify_peer_name' => false,
],
],

as you should never change code in vendors as suggested by Sultan Ahmad

因为您永远不应该按照 Sultan Ahmad 的建议更改供应商中的代码

Editor's note: disabling SSL verification has security implications.Without verification of the authenticity of SSL/HTTPS connections, a malicious attacker can impersonate a trusted endpoint (such as GitHub or some other remote Git host), and you'll be vulnerable to a Man-in-the-Middle Attack. Be sure you fully understand the security issues before using this as a solution.

编者注:禁用 SSL 验证具有安全隐患。如果不验证 SSL/HTTPS 连接的真实性,恶意攻击者可以冒充受信任的端点(例如 GitHub 或其他一些远程 Git 主机),您将容易受到中间人攻击在使用它作为解决方案之前,请确保您完全了解安全问题。

回答by Otrebla

I had the same issue and was able to resolve by removing a level of authentication security. That is, at some point Gmail asked me for the phone number - 2nd level of authentication. When I deleted this 2nd level I was happy again. I hope I have helped.

我遇到了同样的问题,并且能够通过删除身份验证安全级别来解决。也就是说,在某些时候 Gmail 要求我提供电话号码 - 第二级身份验证。当我删除这个第二级时,我又高兴了。我希望我有所帮助。

回答by Josué Leo Moreno

Hi I have also found this very useful on the server level: Edit \vendor\swiftmailer\lib\classes\Swift\Transport\StreamBuffer.phpline 259 ish. comment out the $options = array(); and add the below.

嗨,我也发现这在服务器级别非常有用:编辑\vendor\swiftmailer\lib\classes\Swift\Transport\StreamBuffer.phpline 259 ish。注释掉 $options = array(); 并添加以下内容。

$options = array(); 
$options['ssl'] = array('verify_peer' => false,
'verify_peer_name' => false, 'allow_self_signed' => true);

This work with Laravel 6.0

这适用于 Laravel 6.0

回答by Sultan Ahmad

in Laravel : this will solve the problem. go to \vendor\swiftmailer\swiftmailer\lib\classes\Swift\Transport\StreamBuffer.php

在 Laravel 中:这将解决问题。去 \vendor\swiftmailer\swiftmailer\lib\classes\Swift\Transport\StreamBuffer.php

inside method private function establishSocketConnection()

内部方法私有函数建立SocketConnection()

after this code

在这段代码之后

$options = array();
        if (!empty($this->params['sourceIp'])) {
            $options['socket']['bindto'] = $this->params['sourceIp'].':0';
        }

then add this two lines

然后添加这两行

$options['ssl']['verify_peer'] = FALSE;
$options['ssl']['verify_peer_name'] = FALSE;