0

I have hosting with HostGator, and I am using the PHP Mailer package to connect to the google smtp server and send mail.

Here is the part of my code that connects to the server:

$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPDebug = 1;
$mail->CharSet="UTF-8";
$mail->SMTPSecure = 'ssl';
$mail->Host = 'smtp.gmail.com';
$mail->Port = 465;
$mail->Username = 'user';
$mail->Password = 'pass';
$mail->SMTPAuth = true;

This is the error that im getting:

enter image description here

Perhaps google blocked me from logging in from an external server? If so, how do I permanently fix that? I am sure that my login credentials are correct.

nshah
  • 597
  • 2
  • 9
  • 30
  • i did, and i am sure they are correct! – nshah Sep 10 '13 at 02:25
  • 1
    What about setting SMTPSecure='TLS'? Did you see this? http://phpmailer.worxware.com/?pg=examplebgmail and this: http://stackoverflow.com/questions/11318578/sending-an-email-using-phpmailer-and-gmail-smtp – Matt Sep 10 '13 at 02:28

1 Answers1

0

I ran into similar problems when trying to use Google's SMTP with python (specifically, when using Django). Here were the steps I used to fix the issue (some of them are "well known" and reported in many places, others aren't).

  1. I personally use TSL + port 587. However, SSL + port 465 is also valid (which you have).

  2. Ensure you have the appropriate security settings in gmail. Some of these may not be necessary, but it's what I had to set.

    Settings > Forwarding and POP/IMAP > Enable IMAP Access. Settings > Accounts and Import > Change account settings: > Other Google

    Account Settings > Sign-in & Security > Connected apps & sites > Allow less secure apps (enabled / on).

  3. Finally (and this is the step that made my system work), reset your password.

For whatever reason, I kept getting errors from gmail prompting me to ensure my login was correct / login via browser, despite being absolutely sure the login info was correct (and being able to login with those credentials via browser). However, as soon as I changed the password and tried again, it "magically" worked.

This might just be a security feature gmail has in place where if you've tried to access the gmail via an app before privileges were enabled, then it will block access from unknown apps (or at least that app) until they truly "verify" it's you. But, that's just a guess...

widmo
  • 51
  • 1
  • 7