PHP发送带有SMTP错误的电子邮件:警告:stream_socket_enable_crypto():语言字符串无法加载:tls

I would send email with SMTP in PHP. I use Gmail SMTP.

My code :

<?php

require 'PHPMailer_5.2.0/class.phpmailer.php';

$mail = new PHPMailer;

$mail->IsSMTP();                                      // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com';                 // Specify main and backup server
$mail->Port = 587;                                    // Set the SMTP port
$mail->SMTPAuth = true;                               // Enable SMTP authentication
$mail->Username = 'egenthiers.80@gmail.com';                // SMTP username
$mail->Password = 'XXXX';                  // SMTP password
$mail->SMTPSecure = 'tls';                            // Enable encryption, 'ssl' also accepted

$mail->From = 'egenthiers.80@gmail.com';
$mail->FromName = 'Egen Can';
$mail->AddAddress('egenthiers.63@gmail.com', 'Egen Can');  // Add a recipient

$mail->IsHTML(true);                                  // Set email format to HTML

$mail->Subject = 'Here is the subject';
$mail->Body    = 'This is the HTML message body <strong>in bold!</strong>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

if(!$mail->Send()) {
   echo 'Message could not be sent.';
   echo 'Mailer Error: ' . $mail->ErrorInfo;
   exit;
}

echo 'Message has been sent';
?>

When I run this code. I get this error :

Warning: 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 C:\xampp\htdocs\xxx\PHPMailer_5.2.0\class.smtp.php on line 200 Language string failed to load: tls Message could not be sent.Mailer Error: Language string failed to load: tls SMTP server error:

How can I solve this problem?

I need your help.

dongye3917
dongye3917 PHPMailer的可能重复生成PHP警告:stream_socket_enable_crypto():对等证书与预期不匹配
一年多之前 回复
drt5813
drt5813 我做的。但没有奏效
一年多之前 回复
doushao1087
doushao1087 将其上传到服务器并尝试此操作。默认情况下,localhost不会发送电子邮件,除非您配置它stackoverflow.com/questions/30610387/...
一年多之前 回复

1个回答



错误1:</ p>

  require'PHPMailer_5.2.0 / class.phpmailer.php  '; 
</ code> </ pre>

您使用的是一个非常非常旧的PHPMailer版本,它有很多安全漏洞。 立即升级。</ p>

错误2:</ p> \ n

  OpenSSL错误消息:错误:14090086:SSL例程:ssl3_get_server_certificate:
certificate验证失败
</ code> </ pre>

搜索此错误消息表示您没有找到许多答案并且文档,解决了这个确切的问题。</ p>

文档涵盖 这广泛。 您服务器的CA证书捆绑包很可能已经过时(特别是考虑到您使用的是旧版本的PHPMailer,并且基于一个非常古老的示例,您的代码基于此。)</ p>
</ div>

展开原文

原文

Mistake 1:

require 'PHPMailer_5.2.0/class.phpmailer.php';

You're using a very, very old version of PHPMailer that is buggy and subject to numerous security holes. Upgrade immediately.

Mistake 2:

OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:
certificate verify failed 

Not searching for this error message means that you have not found the many, many answers and documentation that addresses this exact problem.

The documentation covers this extensively. It's most likely that your server's CA certificate bundle is outdated (especially given you're using such an old version of PHPMailer, and have based your code on a very old example).

douzhangbao2187
douzhangbao2187 端口587上的ssl模式将不起作用,因为您会知道您是否阅读了我指向您的文档。 我不打算解决旧版本的问题。
一年多之前 回复
dongpo3957
dongpo3957 你是公正的。 我更改了这个'$ mail-> SMTPSecure =“tls”;' 到ssl。 我解决了这个错误。 但是我得到了其他错误:)这个错误:'警告:fputs()期望参数1是资源,在第215行的C:\ xampp \ htdocs \ xxx \ PHPMailer_5.2.0 \ class.smtp.php中给出的整数SMTP错误: 无法进行身份验证。 消息无法发送.Mailer错误:SMTP错误:无法验证'如果我下载新的PHPMailer,问题是否会解决?
一年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问