This post has evolved from an initial problem where I had copied in code that caused an error due to formatting. I am now struggling with a new error. The inital problem has changed to a redundant one. I will check other posts for a potential fix. I have been following along with a tutorial about how to send email using PHPmailer and SMTP. I am using Xampp localhost. I have installed PHPmailer using composer. I am receiving the error: SMTP Error: Could not authenticate. SMTP Error: Could not authenticate. message could not be sentSMTP Error: Could not authenticate.
Help would be appreciated.
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require_once 'vendor/autoload.php';
$m = new PHPMailer(true);
try{
$m->SMTPDebug = 2;
$m->isSMTP();
$m->Host = 'smtp.gmail.com';
$m->SMTPAuth = true;
$m->Username = 'munsonatl';
$m->Password = ' ';
$m->SMTPSecure = 'SSL';
$m->Port = 465;
$m->setFrom('munsonatl@gmail.com', 'Mailer');
$m->addAddress('munsonatl@gmail.com', 'Matt Macy');
$m->addReplyto('reply@mattmacy.com', 'replyAdress');
$m->Subject = "Here is an Email";
$m->Body = "This is the body of the email";
$m->AltBody = "This is the body of an email";
$m->send();
echo "message has been sent";
} catch (Exception $e){
echo "message could not be sent", $m->ErrorInfo;
}