如何修复 stream_socket_enable_crypto():SSL 操作失败,代码为 1
how to fix stream_socket_enable_crypto(): SSL operation failed with code 1
stream_socket_enable_crypto(): SSL operation failed with code 1.
OpenSSL Error messages: error:14090086:SSL
routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed
我正在使用 Laravel 4.2、PHP 5.6、Apache 2.4
我在 Amazon ec2 中安装了 GoDaddy SSL Linux。
当我使用 https 访问网站时,SSL 工作正常。
调用我的函数时发生错误:
<?php
public function sendEmail()
{
\Mail::send ( 'emails.code.code', $data, function ($sendemail) use($email) {
$sendemail->from ( 'info@me.com', 'Me Team' );
$sendemail->to ( $email, '' )->subject ( 'Activate your account' );
} );
}
?>
我看了一些关于这个的文章,他们说有些东西我们应该做一些改变,他们把那个代码放了但是我不知道在哪里插入它。
和 php http://php.net/manual/en/migration56.openssl.php 的文档很难理解。
所以我的问题是如何解决这个问题?
尝试更改 app/config/email.php
smtp
到 mail
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 Gmail, 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.
我在laravel 4.2中也有这个错误,我是这样解决的。找出 StreamBuffer.php
。对我来说,我使用 xampp 并且我的项目名称是 itis_db 为此,我的路径是这样的。所以尽量按照你的找
C:\xampp\htdocs\itis_db\vendor\swiftmailer\swiftmailer\lib\classes\Swift\Transport\StreamBuffer.php
然后在StreamBuffer.php
里面找出这个函数
private function _establishSocketConnection()
并将这两行粘贴到这个函数中
$options['ssl']['verify_peer'] = FALSE;
$options['ssl']['verify_peer_name'] = FALSE;
并重新加载浏览器并再次尝试 运行 您的项目。我是这样穿的:
private function _establishSocketConnection()
{
$host = $this->_params['host'];
if (!empty($this->_params['protocol'])) {
$host = $this->_params['protocol'].'://'.$host;
}
$timeout = 15;
if (!empty($this->_params['timeout'])) {
$timeout = $this->_params['timeout'];
}
$options = array();
if (!empty($this->_params['sourceIp'])) {
$options['socket']['bindto'] = $this->_params['sourceIp'].':0';
}
$options['ssl']['verify_peer'] = FALSE;
$options['ssl']['verify_peer_name'] = FALSE;
$this->_stream = @stream_socket_client($host.':'.$this->_params['port'], $errno, $errstr, $timeout, STREAM_CLIENT_CONNECT, stream_context_create($options));
if (false === $this->_stream) {
throw new Swift_TransportException(
'Connection could not be established with host '.$this->_params['host'].
' ['.$errstr.' #'.$errno.']'
);
}
if (!empty($this->_params['blocking'])) {
stream_set_blocking($this->_stream, 1);
} else {
stream_set_blocking($this->_stream, 0);
}
stream_set_timeout($this->_stream, $timeout);
$this->_in = &$this->_stream;
$this->_out = &$this->_stream;
}
希望你能解决这个问题.....
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 Gmail, 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.
此问题的简单解决方法可能是编辑 config/mail.php 并关闭 TLS
'encryption' => env('MAIL_ENCRYPTION', ''), //'tls'),
基本上就是这样
$options['ssl']['verify_peer'] = FALSE;
$options['ssl']['verify_peer_name'] = FALSE;
你也应该放松安全,但在第一个选项中没有必要深入研究供应商的代码。
阅读app/config/mailphp
Supported : "smtp", "mail", "sendmail"
根据您机器上安装的邮件实用程序,填写驱动程序密钥的值。我愿意
'driver' => 'sendmail',
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 Gmail, 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.
您可以在 /config/mail.php 中添加以下代码(已在 laravel 5.1、5.2、5.4 上测试和工作)
'stream' => [
'ssl' => [
'allow_self_signed' => true,
'verify_peer' => false,
'verify_peer_name' => false,
],
],
要解决此问题,您首先需要检查要连接的主机的 SSL 证书。例如使用 ssllabs or other ssl tools。在我的例子中,中间证书是错误的。
如果证书没问题,请确保您服务器上的 openSSL 是最新的。 运行 openssl -v
检查您的版本。也许您的版本太旧无法使用证书。
在极少数情况下,您可能希望禁用 ssl 安全功能,例如 verify_peer、verify_peer_name 或 allow_self_signed。请非常小心,永远不要在生产中使用它。这只是临时测试的一个选项。
for Laravel 5.4
for gmail
在 .env 文件中
MAIL_DRIVER=mail
MAIL_HOST=mail.gmail.com
MAIL_PORT=587
MAIL_USERNAME=<username>@gmail.com
MAIL_PASSWORD=<password>
MAIL_ENCRYPTION=tls
在config/mail.php
'driver' => env('MAIL_DRIVER', 'mail'),
'from' => [
'address' => env(
'MAIL_FROM_ADDRESS', '<username>@gmail.com'
),
'name' => env(
'MAIL_FROM_NAME', '<from_name>'
),
],
就我而言,我遵循了
$mail = new PHPMailer;
$mail->isSMTP();
$mail->Host = '<YOUR HOST>';
$mail->Port = 587;
$mail->SMTPAuth = true;
$mail->Username = '<USERNAME>';
$mail->Password = '<PASSWORD>';
$mail->SMTPSecure = '';
$mail->smtpConnect([
'ssl' => [
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
]
]);
$mail->smtpClose();
$mail->From = '<MAILFROM@MAIL.COM>';
$mail->FromName = '<MAIL FROM NAME>';
$mail->addAddress("<SENDTO@MAIL.com>", '<SEND TO>');
$mail->isHTML(true);
$mail->Subject= '<SUBJECTHERE>';
$mail->Body = '<h2>Test Mail</h2>';
$isSend = $mail->send();
$default = [ ... ];
$turnOffSSL = [
'stream' => [
'ssl' => [
'allow_self_signed' => true,
'verify_peer' => false,
'verify_peer_name' => false,
],
],
];
$environment = env('APP_ENV');
if ($environment === 'local') {
return array_merge($default, $turnOffSSL);
}
return $default;
编辑您的 .env 并在邮件配置行之后添加此行
MAIL_ENCRYPTION=""
保存并尝试发送电子邮件
如何修复 Laravel(至少 5、6、7)、WordPress(以及我猜的其他 PHP + cURL
实现):
下载最新的cacert.pem file from cURL website。
wget https://curl.haxx.se/ca/cacert.pem
编辑 php.ini
(您可以 php --ini
找到它),更新(如果它们不存在则创建)这两行:
curl.cainfo="/path/to/downloaded/cacert.pem"
...
openssl.cafile="/path/to/downloaded/cacert.pem"
这些行应该已经存在但被注释掉了,所以取消注释并使用下载的路径编辑这两个值 cacert.pem
重新启动 PHP 和 Nginx/Apache。
编辑:您可能需要 chown/chmod
下载的证书文件,以便 PHP(以及用户 运行 它)可以阅读它。
终于!这是我的 AVG 防病毒软件,它有一个名为电子邮件屏蔽的功能,将其禁用后错误消失了。
今天在我的一台服务器上开始发生这种情况,该服务器使用 wordpress 和一个使用 PHPMailer 的插件,最近没有更改。
解决方法:sudo yum install ca-certificates
现在它再次完美运行,我也重新启动了 httpd(不确定是否需要)
我无法找出真正的问题,我怀疑这是旧 ca-certificates 包中的硬编码日期。
将加密类型从 SSL 更改为 TLS 适合我。
转到vendor\swiftmailer\swiftmailer\lib\classes\Swift\Transport\StreamBuffer。php
评论第 250 行并添加此行:
//$options = [];
$options['ssl'] = array('verify_peer' => false, 'verify_peer_name' => false, 'allow_self_signed' => true);
stream_socket_enable_crypto(): SSL operation failed with code 1.
OpenSSL Error messages: error:14090086:SSL
routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed
我正在使用 Laravel 4.2、PHP 5.6、Apache 2.4
我在 Amazon ec2 中安装了 GoDaddy SSL Linux。
当我使用 https 访问网站时,SSL 工作正常。
调用我的函数时发生错误:
<?php
public function sendEmail()
{
\Mail::send ( 'emails.code.code', $data, function ($sendemail) use($email) {
$sendemail->from ( 'info@me.com', 'Me Team' );
$sendemail->to ( $email, '' )->subject ( 'Activate your account' );
} );
}
?>
我看了一些关于这个的文章,他们说有些东西我们应该做一些改变,他们把那个代码放了但是我不知道在哪里插入它。
和 php http://php.net/manual/en/migration56.openssl.php 的文档很难理解。
所以我的问题是如何解决这个问题?
尝试更改 app/config/email.php
smtp
到 mail
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 Gmail, 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.
我在laravel 4.2中也有这个错误,我是这样解决的。找出 StreamBuffer.php
。对我来说,我使用 xampp 并且我的项目名称是 itis_db 为此,我的路径是这样的。所以尽量按照你的找
C:\xampp\htdocs\itis_db\vendor\swiftmailer\swiftmailer\lib\classes\Swift\Transport\StreamBuffer.php
然后在StreamBuffer.php
里面找出这个函数private function _establishSocketConnection()
并将这两行粘贴到这个函数中
$options['ssl']['verify_peer'] = FALSE;
$options['ssl']['verify_peer_name'] = FALSE;
并重新加载浏览器并再次尝试 运行 您的项目。我是这样穿的:
private function _establishSocketConnection()
{
$host = $this->_params['host'];
if (!empty($this->_params['protocol'])) {
$host = $this->_params['protocol'].'://'.$host;
}
$timeout = 15;
if (!empty($this->_params['timeout'])) {
$timeout = $this->_params['timeout'];
}
$options = array();
if (!empty($this->_params['sourceIp'])) {
$options['socket']['bindto'] = $this->_params['sourceIp'].':0';
}
$options['ssl']['verify_peer'] = FALSE;
$options['ssl']['verify_peer_name'] = FALSE;
$this->_stream = @stream_socket_client($host.':'.$this->_params['port'], $errno, $errstr, $timeout, STREAM_CLIENT_CONNECT, stream_context_create($options));
if (false === $this->_stream) {
throw new Swift_TransportException(
'Connection could not be established with host '.$this->_params['host'].
' ['.$errstr.' #'.$errno.']'
);
}
if (!empty($this->_params['blocking'])) {
stream_set_blocking($this->_stream, 1);
} else {
stream_set_blocking($this->_stream, 0);
}
stream_set_timeout($this->_stream, $timeout);
$this->_in = &$this->_stream;
$this->_out = &$this->_stream;
}
希望你能解决这个问题.....
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 Gmail, 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.
此问题的简单解决方法可能是编辑 config/mail.php 并关闭 TLS
'encryption' => env('MAIL_ENCRYPTION', ''), //'tls'),
基本上就是这样
$options['ssl']['verify_peer'] = FALSE;
$options['ssl']['verify_peer_name'] = FALSE;
你也应该放松安全,但在第一个选项中没有必要深入研究供应商的代码。
阅读app/config/mailphp
Supported : "smtp", "mail", "sendmail"
根据您机器上安装的邮件实用程序,填写驱动程序密钥的值。我愿意
'driver' => 'sendmail',
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 Gmail, 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.
您可以在 /config/mail.php 中添加以下代码(已在 laravel 5.1、5.2、5.4 上测试和工作)
'stream' => [
'ssl' => [
'allow_self_signed' => true,
'verify_peer' => false,
'verify_peer_name' => false,
],
],
要解决此问题,您首先需要检查要连接的主机的 SSL 证书。例如使用 ssllabs or other ssl tools。在我的例子中,中间证书是错误的。
如果证书没问题,请确保您服务器上的 openSSL 是最新的。 运行 openssl -v
检查您的版本。也许您的版本太旧无法使用证书。
在极少数情况下,您可能希望禁用 ssl 安全功能,例如 verify_peer、verify_peer_name 或 allow_self_signed。请非常小心,永远不要在生产中使用它。这只是临时测试的一个选项。
for Laravel 5.4
for gmail
在 .env 文件中
MAIL_DRIVER=mail
MAIL_HOST=mail.gmail.com
MAIL_PORT=587
MAIL_USERNAME=<username>@gmail.com
MAIL_PASSWORD=<password>
MAIL_ENCRYPTION=tls
在config/mail.php
'driver' => env('MAIL_DRIVER', 'mail'),
'from' => [
'address' => env(
'MAIL_FROM_ADDRESS', '<username>@gmail.com'
),
'name' => env(
'MAIL_FROM_NAME', '<from_name>'
),
],
就我而言,我遵循了
$mail = new PHPMailer;
$mail->isSMTP();
$mail->Host = '<YOUR HOST>';
$mail->Port = 587;
$mail->SMTPAuth = true;
$mail->Username = '<USERNAME>';
$mail->Password = '<PASSWORD>';
$mail->SMTPSecure = '';
$mail->smtpConnect([
'ssl' => [
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
]
]);
$mail->smtpClose();
$mail->From = '<MAILFROM@MAIL.COM>';
$mail->FromName = '<MAIL FROM NAME>';
$mail->addAddress("<SENDTO@MAIL.com>", '<SEND TO>');
$mail->isHTML(true);
$mail->Subject= '<SUBJECTHERE>';
$mail->Body = '<h2>Test Mail</h2>';
$isSend = $mail->send();
$default = [ ... ];
$turnOffSSL = [
'stream' => [
'ssl' => [
'allow_self_signed' => true,
'verify_peer' => false,
'verify_peer_name' => false,
],
],
];
$environment = env('APP_ENV');
if ($environment === 'local') {
return array_merge($default, $turnOffSSL);
}
return $default;
编辑您的 .env 并在邮件配置行之后添加此行
MAIL_ENCRYPTION=""
保存并尝试发送电子邮件
如何修复 Laravel(至少 5、6、7)、WordPress(以及我猜的其他 PHP + cURL
实现):
下载最新的cacert.pem file from cURL website。
wget https://curl.haxx.se/ca/cacert.pem
编辑 php.ini
(您可以 php --ini
找到它),更新(如果它们不存在则创建)这两行:
curl.cainfo="/path/to/downloaded/cacert.pem"
...
openssl.cafile="/path/to/downloaded/cacert.pem"
这些行应该已经存在但被注释掉了,所以取消注释并使用下载的路径编辑这两个值 cacert.pem
重新启动 PHP 和 Nginx/Apache。
编辑:您可能需要 chown/chmod
下载的证书文件,以便 PHP(以及用户 运行 它)可以阅读它。
终于!这是我的 AVG 防病毒软件,它有一个名为电子邮件屏蔽的功能,将其禁用后错误消失了。
今天在我的一台服务器上开始发生这种情况,该服务器使用 wordpress 和一个使用 PHPMailer 的插件,最近没有更改。
解决方法:sudo yum install ca-certificates
现在它再次完美运行,我也重新启动了 httpd(不确定是否需要)
我无法找出真正的问题,我怀疑这是旧 ca-certificates 包中的硬编码日期。
将加密类型从 SSL 更改为 TLS 适合我。
转到vendor\swiftmailer\swiftmailer\lib\classes\Swift\Transport\StreamBuffer。php
评论第 250 行并添加此行:
//$options = [];
$options['ssl'] = array('verify_peer' => false, 'verify_peer_name' => false, 'allow_self_signed' => true);