1

I want to know where the problem is because I get authentication error.

  1. I already have a few gmail accounts,
  2. I created a new one for my website,
  3. I added a new email in "Account and import" to my old gmail account.
  4. I copied my new email username and password to phpmailer code
include_once('phpmailer/class.phpmailer.php');
include_once('phpmailer/class.smtp.php');
//6nb5Drv;
function sendmail(){
$mail = new PHPMailer();  

$mail->IsSMTP();                                      // set mailer to use SMTP
$mail->SMTPAuth = true;     // turn on SMTP authentication
$mail->SMTPSecure = "tls";
$mail->Host = "smtp.gmail.com";  // specify main and backup server
$mail->Port = 587; // Set the SMTP port i tried and 457
$mail->Username = 'newmail@gmail.com';                // SMTP username
$mail->Password = 'newmailpass';                  // SMTP password

$mail->SMTPDebug  = 1;                     // enables SMTP debug information (for testing)
                                           // 1 = errors and messages
                                           // 2 = messages only

$mail->From = 'from@yahoo.com';
$mail->FromName = 'From';
$mail->AddAddress('to@gmail.com', 'To');  // Add a recipient

$mail->IsHTML(true);                                  // Set email format to HTML

$mail->Subject = 'Here is the subject';
$mail->Body    = 'This is the HTML message body <strong>in bold!</strong>';
$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;
   exit;
}

echo 'Message has been sent';
}
sendmail();

But I get an authentication error. What is wrong? Probably something with the credentials, how do I configure gmail smtp?

Debug report:

2015-12-04 17:56:15 CLIENT -> SERVER: EHLO www.site.co 2015-12-04 17:56:15 CLIENT -> SERVER: STARTTLS 2015-12-04 17:56:15 CLIENT -> SERVER: EHLO www.site.co 2015-12-04 17:56:15 CLIENT -> SERVER: AUTH LOGIN 2015-12-04 17:56:15 CLIENT -> SERVER: UHJlZGljdG9sb2d5 2015-12-04 17:56:15 CLIENT -> SERVER: U2dHZlB0VHZUbTZ1SW9ZMi1qTlNCQQ== 2015-12-04 17:56:17 SMTP ERROR: Password command failed: 435 4.7.8 Error: authentication failed: UGFzc3dvcmQ6 2015-12-04 17:56:17 SMTP Error: Could not authenticate. 2015-12-04 17:56:17 CLIENT -> SERVER: QUIT 2015-12-04 17:56:17 SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting Message could not be sent.Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

Mike Beeler
  • 4,081
  • 2
  • 29
  • 44
DocNet
  • 460
  • 3
  • 9
  • 24
  • Base your code on [the gmail example provided with PHPMailer](https://github.com/PHPMailer/PHPMailer/blob/master/examples/gmail.phps), not some old and obsolete copy. Use the Autoloader. [Read the docs](https://github.com/PHPMailer/PHPMailer/wiki). – Synchro Dec 04 '15 at 20:02
  • If you set `SMTPDebug = 2` (and ignore the wrong description of it in your code), you will see why gmail is rejecting your login. – Synchro Dec 04 '15 at 20:09

1 Answers1

2

According to this post: PHPMailer - SMTP ERROR: Password command failed when send mail from my server, in some case, you have to specify google that this is not a suspicious activity and activate some less secure option in your account.
Assuming this is the right password...

Community
  • 1
  • 1
TGrif
  • 5,725
  • 9
  • 31
  • 52
  • You don't have to do that, though it is the simplest way. The alternative is to [read the docs](https://github.com/PHPMailer/PHPMailer/wiki) and implement it properly. – Synchro Dec 04 '15 at 20:00
  • Hey, intersting was happend now. Once they send me mail, but when i try again i get authentication error again. – DocNet Dec 04 '15 at 20:20
  • @Synchro The doc redirects to google _Allow less secure apps_ and google _XOAUTH2_ mechanism anyway... – TGrif Dec 04 '15 at 20:25
  • This is new Please log in with your web browser and then try again. Learn more at534 5.7.9 https://support.google.com/mail/answer/78754 m67sm4963214wmf.16 - gsmtp SMTP ERROR: Password command failed: 534-5.7.9 Please log in with your web browser and then try again. Learn more at534 5.7.9 https://support.google.com/mail/answer/78754 m67sm4963214wmf.16 - gsmtp – DocNet Dec 04 '15 at 20:25
  • It's not new. It just wasn't visible because you didn't show enough debug output before. Painful though it is, the proper fix is to implement xoauth2. If you enable less secure apps, you still need to do what it says and log in via a browser. – Synchro Dec 05 '15 at 12:42
  • I solve it when i allow less secure apps to use gmail and displaycaptcha. Thanks, you both help me. – DocNet Dec 05 '15 at 21:01