I have never received the following error when working with PHPMailer:
2021-11-23 03:10:20 SERVER -> CLIENT: 535-5.7.8 Username and Password not accepted.
2021-11-23 03:10:20 SMTP ERROR: Password command failed: 535-5.7.8 Username and Password not accepted.
I am indeed entering the correct username and password. Here is the code:
<?php
use phpmailer\PHPMailer\PHPMailer;
require_once '../phpmailer/PHPMailer.php';
require_once '../phpmailer/SMTP.php';
require_once '../phpmailer/Exception.php';
$mail = new PHPMailer;
$mail->SMTPDebug = 4;
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = '[email protected]';
$mail->Password = 'somepassword';
$mail->SMTPSecure = 'tls';
$mail->Port = 25;
$mail->setFrom('[email protected]', 'Mailer');
$mail->addAddress('[email protected]', 'Receiver');
$mail->addReplyTo('[email protected]', 'No Reply');
$mail->Body = $body;
$mail->isHTML(true);
if($mail->send()){
echo "Email sent";
} else {
echo "Error: There was an error sending email " . $mail->ErrorInfo;;
}
?>
I have tried to user the answer found here: Username and Password not accepted
And here: Username and Password not accepted
No luck.
I am using the correct username and password.
I changed the port to 465 and got the following error:
2021-11-23 03:20:20 Connection: opening to smtp.gmail.com:465, timeout=300, options=array()<br>
2021-11-23 03:20:20 Connection: opened<br>
2021-11-23 03:20:30 SMTP INBOUND: ""<br>
2021-11-23 03:20:30 SERVER -> CLIENT: <br>
2021-11-23 03:20:30 Connection: closing due to error<br>
2021-11-23 03:20:30 Connection: closed<br>
SMTP connect() failed.
https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting<br>
Error: There was an error sending email SMTP connect() failed.
https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
What am I doing wrong?
SMTPSecure
use'tls'
. If you enabled 2 step verification, please create app password for use with your code.ssl
mode on port 465 is the preferred config, though it's easier to diagnose TLS problems withtls
mode on port 587. Failing to create a TLS connection suggests that your PHP configuration may be outdated, or that your OS may have an outdated CA certificate bundle. Please read the guide the error message links to more info on how to diagnose it further.