Trouble Sending Email via Gmail SMTP Server with PHP Mailer: "SMTP AUTH is Required" Error
When attempting to send an email through the Gmail SMTP server using PHP Mailer, you may encounter an error indicating that SMTP authentication is necessary for message submission on port 587. This issue can be resolved by implementing the following steps:
Sample Working Code:
This revised sample code may help you resolve the issue:
$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 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"; }
This code has been tested and verified to work. By implementing these suggestions, you should be able to successfully send emails through the Gmail SMTP server using PHP Mailer.
The above is the detailed content of Why am I getting an 'SMTP AUTH is Required' error when sending emails via Gmail's SMTP server using PHP Mailer?. For more information, please follow other related articles on the PHP Chinese website!