I have been using PHPMailer for several months to send email OTP verification and automated alerts from my website using a regular @gmail.com account. This setup has been working flawlessly until last week. Now, all new users who register on my website are not receiving the OTP email for verification. Instead, I receive a “Message Rejected” error, and the emails bounce back to the sending email address.
Details
Email Setup: Using a regular @gmail.com account with App Passwords for authentication.
Mailer Configuration: PHPMailer with SMTP settings.
Environment: The issue occurs both on the live server and locally using XAMPP.
Code Snippet –
function sendOTP($email, $otp, $name) {
$credentials = include 'detail.php';
$mail = new PHPMailerPHPMailerPHPMailer();
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = $credentials['email'];
$mail->Password = $credentials['password'];
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
$mail->setFrom($credentials['email'], 'noreply');
$mail->addAddress($email);
$mail->isHTML(true);
$mail->Subject = 'OTP to Login to #######';
$mail->Body = '<div style="font-family: Aptos, Arial, sans-serif; color: #333; background-color: #f4f4f4; padding: 20px;">
<div style="max-width: 600px; margin: 0 auto; background-color: #ffffff; padding: 20px; border-radius: 8px; box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);">
<div style="text-align: center;">
<img src="https://drive.google.com/id=#################" alt="########" style="max-width: 150px;">
</div>
<div style="font-size: 21px; text-align: center; font-weight: bold; margin-bottom: 10px;">########</div>
<p style="font-size: 18px;">Dear ' . htmlspecialchars($name) . ',</p>
<p style="font-size: 18px;">Your One Time Password to Login to your Account is:</p>
<div style="background-color: #007BFF; color: #ffffff; padding: 10px; border-radius: 5px; text-align: center; font-size: 20px; margin-bottom: 15px;">
<b style="font-size: 22px;">' . $otp . '</b>
</div>
<p style="font-size: 15.5px;">This is an auto-generated message, please <b>DO NOT</b> reply to this message/E-Mail ID.</p>
<br>
<p style="font-size: 18px;">Regards,<br>########</p>
<p style="font-size: 18px;">URL of request: ###########.com/user_login.php</p>
</div>
</div>';
if (!$mail->send()) {
error_log('Mailer Error: ' . $mail->ErrorInfo);
}
}
?>
Troubleshooting Steps Taken
Verified the sending email address is not blocked or marked as spam.
Checked email quotas and limitations, and none are exceeded.
Ran the same setup locally on XAMPP and encountered the same issue.
I am looking for guidance on why the emails are being rejected and how to resolve this issue. Any help or insights into potential causes and solutions would be greatly appreciated.
Thank you in advance.
jadhav kumar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.