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?