Unable to send email using Gmail SMTP server through PHPMailer, getting error: SMTP AUTH is required for message submission on port 587. How to fix?
$mail = new PHPMailer(); // create a new object
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only
$mail->SMTPAuth = true; // authentication enabled
$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for Gmail
$mail->Host = "smtp.gmail.com";
$mail->Port = 465; // or 587
$mail->IsHTML(true);
$mail->Username = "email@gmail.com";
$mail->Password = "password";
$mail->SetFrom("example@gmail.com");
$mail->Subject = "Test";
$mail->Body = "hello";
$mail->AddAddress("email@gmail.com");
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message has been sent";
}
This code above has been tested and worked for me.
It could be that you needed $mail->SMTPSecure = 'ssl';
Also make sure you don't have two step verification switched on for that account as that can cause problems also.
UPDATED
You could try changing $mail->SMTP to:
$mail->SMTPSecure = 'tls';
It's worth noting that some SMTP servers block connections.
Some SMTP servers don't support SSL
(or TLS
) connections.
Use php mailer to send via Gmail - SMTP error
This is possible duplicate of Unable to send email using Gmail SMTP server through PHPMailer, getting error: SMTP AUTH is required for message submission on port 587. How to fix?
Probably you didn't allow for less secured apps in Gmail account security dashboard.
Related Topics
How to Get the Query Builder to Output Its Raw SQL Query as a String
File_Put_Contents - Failed to Open Stream: Permission Denied
How to Catch the Fatal Error: Maximum Execution Time of 30 Seconds Exceeded in PHP
How to Create a Comma-separated List from an Array in PHP
Permutations - All Possible Sets of Numbers
Convert Time in Hh:Mm:Ss Format to Seconds Only
Target Class Controller Does Not Exist - Laravel 8
How to Force File Download With PHP
How to Set Up File Permissions For Laravel
Difference Between Require, Include, Require_Once and Include_Once
PHP: Return All Dates Between Two Dates in an Array
How to Get Innerhtml of Domnode