简体   繁体   中英

PHP sending email with SMTP error : Warning: stream_socket_enable_crypto():Language string failed to load: 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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM