2

I'm about to deploy a website in the next 8h and Gmail just stop accepting PHPmailer sign in to my account. At first it worked, for a bunch of hours while testing. Then, it just stopped working.. I already allowed all the allow less secure apps to sign in from gmail but it just still don't allow phpmailer to sign in. I want to jump off a cliff!

Here is the same code that worked brilliant a few hours ago:

$mail->SMTPDebug = 0;
$mail->isSMTP();
$mail->Host = "smtp.gmail.com";
$mail->SMTPAuth = true;
$mail->Username = 'myemail@gmail.com';
$mail->Password = 'password';
$mail->SMTPSecure = 'ssl';
$mail->Port = 587;

Then for some reason gmail just started blocking the sign in attemps. I hope I could get some help here, I already looked for over an hour and still got nothing.

Thanks!

Touheed Khan
  • 2,149
  • 16
  • 26
Ed91gg
  • 307
  • 3
  • 13
  • 1
    Check last comment on this: https://stackoverflow.com/a/33667250/1485183 – Amit Merchant Feb 20 '18 at 08:01
  • 1
    I had the same issue in the past, and it has been resolved by enabling less secure apps like described in @AmitMerchant's link. – teeyo Feb 20 '18 at 08:03
  • 1
    @AmitMerchant thanks! I never saw that around the web.. Just did that, plus seems that gmail doesn't accept port 587 even with the "allow access to less secure apps" enabled. Switched to 465 and started working. Thanks, I'll answer my own question with the link you provided as well. Thank you. – Ed91gg Feb 20 '18 at 08:08

1 Answers1

5

Resolved! I hope this helps others in the future.. Even though I enabled gmail "access to less secure apps" it kept rejecting the PHPmailer sign in.. Seems that for some reason gmail wasn't accepting port 587, at least for me, so I switched it to 465 and everything started working right a way.

As a plus for this answer, as for what @Amit Merchant suggested in the comment section, I wasn't aware of what the last comment in stackoverflow.com/a/33667250/1485183 says, it basically shows a gmail feature I never found or heard when looking for a solution for my problem, that this: accounts.google.com/DisplayUnlockCaptcha

I'm sure this will help someone some day whether if it's for phpmailer or any other library.

Ed91gg
  • 307
  • 3
  • 13
  • The DisplayUnlockCaptcha tip is in [the PHPMailer troubleshooting guide](https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting). Also you don't need to enable "less secure apps" if you use XOAUTH2 authentication. It's very painful to set up, but it avoids this problem with gmail - see the examples provided with PHPMailer for how to use it. – Synchro Feb 20 '18 at 10:32
  • @Synchro Thanks, I will definitely give this a try and come back to update my answer in case everything worked fine, so to disable de "less secure apps". Thank you. – Ed91gg Feb 20 '18 at 16:27