Big problem with PHPMailer, I can not get it to send emails [attached error]

0

I'm running a script that sends emails, but I can not get it to work.

This is my code. Any comments?:

<?php
// Import PHPMailer classes into the global namespace
// These must be at the top of your script, not inside a function
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

//Load composer's autoloader
require 'vendor/autoload.php';

$mail = new PHPMailer(true);                              // Passing 'true' enables exceptions
try {
//Server settings
$mail->SMTPDebug = 2;                                 // Enable verbose debug output
$mail->isSMTP();                                      // Set mailer to use SMTP
$mail->Host = 'smtp.serviciodecorreo.es';  // Specify main and backup SMTP servers
$mail->SMTPAuth = true;                               // Enable SMTP authentication
$mail->Username = 'admin@*****.**';                 // SMTP username
$mail->Password = '********';                           // SMTP password
$mail->SMTPSecure = 'ssl';                            // Enable TLS encryption, 'ssl' also accepted
$mail->Port = 465;                                    // TCP port to connect to

//Recipients
$mail->setFrom('admin@*****.**');
$mail->addAddress('******@**.com');     // Add a recipient



//Content
$mail->isHTML(true);                                  // Set email format to HTML
$mail->Subject = 'Here is the subject';
$mail->Body    = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

$mail->send();
echo 'Message has been sent';
} catch (Exception $e) {
echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
}

?>

I changed the debug to value 3 and this is what I get. Does anyone know what happens?

2018-02-23 09:05:56 Connection: opening to 
ssl://smtp.serviciodecorreo.es:465, timeout=300, options=array()
2018-02-23 09:05:56 Connection failed. Error #2: stream_socket_client(): SSL 
operation failed with code 1. OpenSSL Error messages:error:14090086:SSL 
routines:ssl3_get_server_certificate:certificate verify failed 
[C:\inetpub\SIADE\PHPMAIL\vendor\phpmailer\phpmailer\src\SMTP.php line 325]
2018-02-23 09:05:56 Connection failed. Error #2: stream_socket_client(): 
Failed to enable crypto 
[C:\inetpub\SIADE\PHPMAIL\vendor\phpmailer\phpmailer\src\SMTP.php line 325]
2018-02-23 09:05:56 Connection failed. Error #2: stream_socket_client(): 
unable to connect to ssl://smtp.serviciodecorreo.es:465 (Unknown error) 
[C:\inetpub\SIADE\PHPMAIL\vendor\phpmailer\phpmailer\src\SMTP.php line 325]
2018-02-23 09:05:56 SMTP ERROR: Failed to connect to server: (0)
SMTP connect() failed. 
https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Message could not be sent. Mailer Error: SMTP connect() failed. 
https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

Will it have something to do with the configuration of the IIS?

    
asked by Pelayo 22.02.2018 в 16:28
source

1 answer

1

PHP 5.6 introduces verification of the SSL certificate. It is the same as an SSL certificate for a web server: it must match the domain, it must be signed by a trusted CA and it must have a SHA2 hash and a 2048 bit key. If you do not want to reconfigure your server, it is possible to force your script to return to the behavior prior to the verification of the certificates, that is, to tell it not to verify the certificate. In this way, you will stop getting error by incorrect certificate

$mail->SMTPOptions = array( 'ssl' => array( 'verify_peer' => false, 'verify_peer_name' => false, 'allow_self_signed' => true )); 
    
answered by 22.02.2018 / 17:49
source