drexlz0623 2019-01-16 05:33
浏览 374

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.

  • 写回答

1条回答 默认 最新

  • dongyilai4214 2019-01-16 08:10
    关注

    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).

    评论

报告相同问题?

悬赏问题

  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 有没有帮写代码做实验仿真的
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥30 vmware exsi重置后登不上
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题
  • ¥20 yolov5自定义Prune报错,如何解决?
  • ¥15 电磁场的matlab仿真