Unable to Send Email Using Gmail SMTP Server Through PHPMailer: SMTP AUTH Required on Port 587
When attempting to send email through the Gmail SMTP server using PHPMailer but encountering an error stating "SMTP AUTH is required for message submission on port 587," several measures can be taken to resolve the issue.
The provided code sample for PHP Mailer should be adjusted as follows:
$mail = new PHPMailer(); $mail->IsSMTP(); $mail->SMTPDebug = 1; // Enables debugging $mail->SMTPAuth = true; $mail->SMTPSecure = 'ssl'; // Secure transfer using SSL $mail->Host = "smtp.gmail.com"; $mail->Port = 465; // SMTP port $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"; }
It is necessary to ensure that SSL is enabled using $mail->SMTPSecure = 'ssl'. If this does not resolve the issue, consider changing to TLS using $mail->SMTPSecure = 'tls'.
It is also essential to verify that two-step verification is disabled for the account being used to send the email, as it can interfere with the process.
Finally, it's important to note that some SMTP servers do not support SSL or TLS connections and may require alternative configurations.
The above is the detailed content of Why Am I Getting 'SMTP AUTH Required' When Sending Emails via Gmail's SMTP Server with PHPMailer?. For more information, please follow other related articles on the PHP Chinese website!