PHPMailer - OpenSSL Error

According to the example that PHPMailer provides, I have a script below,

date_default_timezone_set('Etc/UTC'); require './PHPMailerAutoload.php'; $mail = new PHPMailer; $mail->isSMTP(); $mail->SMTPDebug = 2; $mail->Debugoutput = 'html'; $mail->Host = 'smtp.gmail.com'; $mail->Port = 587; $mail->SMTPSecure = 'tls'; $mail->SMTPAuth = true; $mail->Username = " myemail@example.com "; $mail->Password = "********"; $mail->setFrom(' myMail@example.com ', 'First Last'); $mail->addReplyTo(' myEmail@example.com ', 'First Last'); $mail->addAddress(' toEmail@example.com ', 'first last'); $mail->Subject = 'PHPMailer GMail SMTP test'; $mail->Body = "example"; $mail->AltBody = 'This is a plain-text message body'; if (!$mail->send()) { echo "Mailer Error: " . $mail->ErrorInfo; } else { echo "Message sent!"; } 

Even if this is exactly the same as the original example, I cannot get it to work.

The error I get is

Warning : stream_socket_enable_crypto (): SSL operation completed with code 1. OpenSSL Error messages: error: 14090086: SSL procedures: SSL3_GET_SERVER_CERTIFICATE: certificate verification failed / opt / lampp / htdocs / webmail _client_practise / class.smtp.php on line 344 SMTP Error: Failed to connect to the SMTP host.

Note: The OpenSSL extension in my php.ini file is already open.

+5
source share
2 answers

This is because you are using PHP 5.6 and checking your certificates, but invalid certificates are displayed on your server, so it does not work. Both PHPMailer and PHP are correct in what they do - the code is not to blame. You can either fix your mail server or do what it offers in the troubleshooting guide , which:

 $mail->SMTPOptions = array( 'ssl' => array( 'verify_peer' => false, 'verify_peer_name' => false, 'allow_self_signed' => true ) ); 

And as the manual says, you should not do this, unless you need it - it undermines your safety.

+20
source

Warning: stream_socket_enable_crypto (): SSL operation failed with code 1. OpenSSL error messages: error: 1416F086: SSL procedure: tls_process_server_certificate: certificate verification failed in C: \ xampp \ htdocs \ aaa \ class \ class.smtp.php on the line 254

I need help how to solve this problem in all possible ways. !!!!!!!!!!

0
source

Source: https://habr.com/ru/post/1231945/


All Articles