Reputation: 11
I'm trying to use PHPMailer to send e-mail from my local virtual host on XAMPP with the code below. I have enabled extension=php_openssl.dll in php.ini, still I get the error messages below. Anyone knows why?
require_once 'PHPMailerAutoload.php';
require_once 'class.phpmailer.php';
require_once 'class.smtp.php';
$mail = new PHPMailer(true);
$mail->IsSMTP();
$mail->SMTPDebug = 2;
$mail->SMTPAuth = true;
$mail->SMTPSecure = "tls";
$mail->Host = "smtp.gmail.com";
$mail->Port = 587;
$mail->Username = "xxx";
$mail->Password = "xxx";
$email = "[email protected]";
$name = "Test";
$email_from = "[email protected]";
$name_from = "Test";
$mail->AddAddress($email, $name);
$mail->SetFrom($email_from, $name_from);
$mail->Subject = "My Subject";
$mail->Body = "Mail contents";
try{
$mail->Send();
echo "Success!";
} catch(Exception $e){
echo "Fail - " . $mail->ErrorInfo;
}
Error output: SMTP ERROR: Password command failed: 534-5.7.14 SMTP Error: Could not authenticate.
Upvotes: 0
Views: 667
Reputation: 313
For those having issues with failing authentication using PHPMailer, and all settings and credentials are good, try using this:
$mail->AuthType = 'LOGIN';
in the PHP that is attempting to send the email.
I struggled for the longest, until I added this.
Cheers.
Upvotes: 0