I'm trying to send mail using phpmailer 6.0. I updated my php version and I made my mail "verify less secure apps " because I'm using gmail.
I get an error like this:
2017-12-09 23:30:09 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
I'm using sample code from the readme file.
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;
require 'PHPMailer-master/src/PHPMailer.php';
require 'PHPMailer-master/src/SMTP.php';
require 'PHPMailer-master/src/Exception.php';
$mail = new PHPMailer(true);
try {
$mail->SMTPDebug = 2;
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = 'username@gmail.com';
$mail->Password = 'password';
$mail->SMTPSecure = 'ssl';
$mail->Port = 465;
$mail->setFrom('username@gmail.com');
$mail->addAddress('username@gmail.com');
$mail->isHTML(true);
$mail->Subject = 'hello';
$mail->Body = 'dasdasd';
$mail->AltBody = 'dasdasd';
$mail->send();
echo 'Message has been sent';
} catch (Exception $e) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
}
?>
*note I am not using composer because there isn't any vendor folder when I download the phpmailer.