0
votes

I have problem about sending mails with Google SMTP and latest version of PHPMailer. Here are a lot of questions, but the answers doesn't work for me. I am using free hosting with free subdomain 000webhost. This is my standard PHP code for sending email from PHPMailer docs:

$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = 'GMAIL EMAIL ACCOUNT';
$mail->Password = 'MY PASSWORD FOR GMAIL EMAIL ACCOUNT';
$mail->SMTPSecure = 'tlc';
$mail->Port = 587;
$mail->SMTPDebug  = 3;
$mail->setFrom('EMAIL ADDRESS', 'EXAMPLE');
$mail->addAddress('ADDRESS TO SEND', 'From contact form');

$mail->addCC('[email protected]');
$mail->addBCC('[email protected]');

$mail->Subject = 'Here is the subject';
$mail->Body    = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

if(!$mail->send()) {
    echo 'Message could not be sent.';
    echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
    echo 'Message has been sent';
}

and I get this error:

.... 2017-06-03 15:15:33 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 203sm11822739ywk.62 - gsmtp 2017-06-03 15:15:33 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 203sm11822739ywk.62 - gsmtp 2017-06-03 15:15:33 SMTP Error: Could not authenticate. .....

I see same error if I use ssl with port 465.

In my Gmail email account 2-factory authentication is OFF and Allow less secure apps is ON.

I really don't know what to do.

2
No such setting as tlc for SMTPSecure.Synchro

2 Answers

0
votes

I found a way with creating Google App Password and use it instead Gmail account password:

$mail->Password = 'GOOGLE APP PASSWORD';

To create an app password you need to set Two factory authentication: https://support.google.com/accounts/answer/185839?hl=en, then you can create app password - https://support.google.com/accounts/answer/185833?hl=en

0
votes
  1. Log into your Google account at https://myaccount.google.com
  2. Click on "Security" in the left-hand menu.
  3. Scroll down to the "Less secure app access" section.

    Click "Turn on access (not recommended)".

https://support.google.com/mail/thread/23875320?hl=en