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 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 matlab有关常微分方程的问题求解决
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?
  • ¥100 求三轴之间相互配合画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考