Home > Backend Development > PHP Tutorial > Why Am I Getting the 'SMTP AUTH is Required' Error When Sending Emails via Gmail's SMTP Server with PHPMailer?

Why Am I Getting the 'SMTP AUTH is Required' Error When Sending Emails via Gmail's SMTP Server with PHPMailer?

Patricia Arquette
Release: 2024-12-31 20:39:09
Original
292 people have browsed it

Why Am I Getting the

Unable to Send Email Using Gmail SMTP Server Through PHPMailer: "SMTP AUTH is Required for Message Submission on Port 587"

In the desire to transmit emails with Gmail's SMTP (Simple Mail Transfer Protocol) server through PHP Mailer, one might encounter the error message "SMTP AUTH is required for message submission on port 587." This hindrance signals a requirement for enhanced security measures.

To resolve this issue, consider incorporating the following code modifications:

$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPDebug = 1;
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'ssl';
$mail->Host = "smtp.gmail.com";
$mail->Port = 465;
$mail->IsHTML(true);
$mail->Username = "[email protected]";
$mail->Password = "password";
$mail->SetFrom("[email protected]");
$mail->Subject = "Test";
$mail->Body = "hello";
$mail->AddAddress("[email protected]");

if (!$mail->Send()) {
    echo "Mailer Error: " . $mail->ErrorInfo;
} else {
    echo "Message has been sent";
}
Copy after login

In particular, pay attention to these crucial adjustments:

  • Use $mail->SMTPSecure = 'ssl'; for enhanced connection security.
  • Disable two-step verification for the designated email account.
  • Allow less secure apps to access your Google account by following the instructions provided here: https://myaccount.google.com/lesssecureapps

Alternatively, you might opt to modify the $mail->SMTP setting to:

$mail->SMTPSecure = 'tls';
Copy after login

Bear in mind that certain SMTP servers may impede connections or lack SSL/TLS support. It's advisable to verify with the server administrator to confirm compatibility.

With these adjustments in place, anticipate seamless email transmission through Gmail's SMTP server using PHP Mailer.

The above is the detailed content of Why Am I Getting the 'SMTP AUTH is Required' Error When Sending Emails via Gmail's SMTP Server with PHPMailer?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template