I'm trying to send an email using PHPMailer, and here is my php code
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'vendor/autoload.php';
$mail = new PHPMailer(true);
try {
$mail->SMTPDebug = 2;
$mail->isSMTP();
use SMTP
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = 'abc@gmail.com';
$mail->Password = 'password';
$mail->SMTPSecure = 'ssl';
$mail->Port = 465;
$mail->setFrom('from@example.com', 'Mailer');
$mail->addAddress('efg@gmail.com', 'Joe User');
$mail->addAddress('hij@gmail.com');
$mail->addReplyTo('info@example.com', 'Information');
$mail->addCC('cc@example.com');
$mail->addBCC('bcc@example.com');
$mail->isHTML(true);
$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;
}
?>
and here is the result from the terminal when I run my php code locally
SMTP ERROR: Failed to connect to server: (0)
2018-05-08 00:13:48 SMTP connect() failed.
Message could not be sent. Mailer Error: SMTP connect() failed.
when I comment out $mail->isSMTP(); it said that the message was sent successfully, but I didn't get the e-mail and I don't know if the problem is I'm running my code locally that I need to put it into XAMPP to test it, or there is something wrong with my SMTP configuration, thanks