I'm trying to send myself a mail on my Gmail address, using PhpMailer on a WAMP local server. Here is my code:
require('PHPMailer-master/class.phpmailer.php');
include("PHPMailer-master/class.smtp.php");
[...]
$mail = new PHPMailer();
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'ssl';
$mail->SMTPDebug = 2;
$mail->Port = 465;
$mail->isHTML();
$mail->Username = "myself@gmail.com";
$mail->Password = "mypassword";
$mail->SetFrom('myself@gmail.com', 'Myself Myself');
// I get the destination address from a simple form, which I'm sure works.
$mail->AddAddress($_POST['email'], $_POST['name']);
$mail->Subject = 'Welcome';
// Message
$mail->MsgHTML('Test');
if(!$mail->send()) {
echo 'Error : ' . $mail->ErrorInfo;
} else {
echo 'Message sent !';
}
But I get the following errors on the debug log:
2017-01-01 18:45:28 Connection: opening to smtp.gmail.com:587, timeout=300, options=array ( ) 2017-01-01 18:45:28 Connection: opened 2017-01-01 18:45:29 SERVER -> CLIENT: 220 smtp.gmail.com ESMTP x142sm15027809lfa.32 - gsmtp 2017-01-01 18:45:29 CLIENT -> SERVER: EHLO 127.0.0.1 2017-01-01 18:45:29 SERVER -> CLIENT: 250-smtp.gmail.com at your service, [2.69.179.123] 250-SIZE 35882577 250-8BITMIME 250-STARTTLS 250-ENHANCEDSTATUSCODES 250-PIPELINING 250-CHUNKING 250 SMTPUTF8 2017-01-01 18:45:29 CLIENT -> SERVER: STARTTLS 2017-01-01 18:45:29 SERVER -> CLIENT: 220 2.0.0 Ready to start TLS 2017-01-01 18:45:30 CLIENT -> SERVER: EHLO 127.0.0.1 2017-01-01 18:45:30 SERVER -> CLIENT: 250-smtp.gmail.com at your service, [2.69.179.123] 250-SIZE 35882577 250-8BITMIME 250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH 250-ENHANCEDSTATUSCODES 250-PIPELINING 250-CHUNKING 250 SMTPUTF8 2017-01-01 18:45:30 CLIENT -> SERVER: AUTH LOGIN 2017-01-01 18:45:30 SERVER -> CLIENT: 334 VXNlcm5hbWU6 2017-01-01 18:45:30 CLIENT -> SERVER: cGV5cm9jaGVwaWVycmVAZ21haWwuY29t 2017-01-01 18:45:30 SERVER -> CLIENT: 334 UGFzc3dvcmQ6 2017-01-01 18:45:30 CLIENT -> SERVER: WmJLNmN2bTJyVg== 2017-01-01 18:45:30 SERVER -> CLIENT: 535-5.7.8 Username and Password not accepted. Learn more at 535 5.7.8 https://support.google.com/mail/?p=BadCredentials x142sm15027809lfa.32 - gsmtp 2017-01-01 18:45:30 SMTP ERROR: Password command failed: 535-5.7.8 Username and Password not accepted. Learn more at 535 5.7.8 https://support.google.com/mail/?p=BadCredentials x142sm15027809lfa.32 - gsmtp 2017-01-01 18:45:30 SMTP Error: Could not authenticate. 2017-01-01 18:45:30 CLIENT -> SERVER: QUIT 2017-01-01 18:45:30 SERVER -> CLIENT: 221 2.0.0 closing connection x142sm15027809lfa.32 - gsmtp 2017-01-01 18:45:30 Connection: closed 2017-01-01 18:45:30 SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting Erreur : SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
On my Google Account, I changed the security paramters to accept "less-secured applications". I also tried to change to SSL with port 465, it did not work either.
There seems to be something going on with OAuth, but I have no idea what to do. I checked similar questions on StackOverflow, but none of the given solutions work for me.
If someone could help be with that, I would be very grateful. Thank you very much.