Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHPMailer - SMTP ERROR: Password command failed when send mail from my server

I have used phpmailer() concept to send mail to users from my shared server using php script, but I'm not able to send even though everything is right in my script according to phpmailer code.

My code like this:

  $message = " This is testing message from my server";    $mail = new PHPMailer(); // create a new object   $mail->IsSMTP(); // enable SMTP   $mail->Host = "smtp.gmail.com";   $mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only   $mail->SMTPAuth = true; // authentication enabled   $mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for GMail   $mail->Port = 465; // or 587   $mail->IsHTML(true);   $mail->Username = "[email protected]"; // My gmail username   $mail->Password = "************"; // My Gmail Password   $mail->SetFrom("[email protected]");   $mail->Subject = "Test Mail from my Server";   $mail->Body = $message;   $mail->AddAddress($email);    if($mail->Send())       {     print json_encode("SUCCESS"); } else {     echo "Mailer Error: " . $mail->ErrorInfo;  } 

Note: I have used " GMail " as my SMTP server and SMTPSecure is " ssl " and port is "465" and username & passwords are my GMail username & password

I used VPS shared server and I kept my php script on that server.

I think there is no problem in my php script and I don't know why it doesn't work.

I got the ERROR like this.

  2014-02-21 12:30:11   CLIENT -> SERVER: EHLO jkcorporates.com   2014-02-21 12:30:11   CLIENT -> SERVER: AUTH LOGIN   2014-02-21 12:30:11   CLIENT -> SERVER: bW9vcnRoaS5tcmsxMEBnbWFpbC5jb20=   2014-02-21 12:30:11   CLIENT -> SERVER: OTk0MTI0MTE0MA==   2014-02-21 12:30:11   SMTP ERROR: Password command failed: 534-5.7.14    534-5.7.14 i-_eumA> Please log in via your web browser and then try again.   534 5.7.14 54 k76sm17979938yho.18 - gsmtp   2014-02-21 12:30:11   CLIENT -> SERVER: QUIT   " The ERROR is  "  SMTP connect() failed. 

Please give some solution for that.
Thanks in Advance.

Remember: I use Shared Server Name 'VPS.mydomain.com' and I want to use GMail as my SMTP server to send mail to users.

like image 599
Punniyam Moorthi Avatar asked Feb 21 '14 14:02

Punniyam Moorthi


People also ask

How do I fix SMTP failed to connect to server?

Change the server's SMTP restrictions. Then, add the specified website user to the list of users who are authorized to initiate outbound SMTP connections. Edit PHPMailer's configuration settings, such as host and port. Correct DNS resolution for the mail server.

What is SMTP username and password in PHPMailer?

Scroll the page on the left side SMTP details are available. Username, password, Outgoing host is been used for PHPMailer configuration. Using 587 port instead of 465.


2 Answers

A bit late, but perhaps someone will find it useful.

Links that fix the problem (you must be logged into google account):

https://security.google.com/settings/security/activity?hl=en&pli=1

https://www.google.com/settings/u/1/security/lesssecureapps

https://accounts.google.com/b/0/DisplayUnlockCaptcha

Some explanation of what happens:

This problem can be caused by either 'less secure' applications trying to use the email account (this is according to google help, not sure how they judge what is secure and what is not) OR if you are trying to login several time in a row OR if you change countries (for example use VPN, move code to different server or actually try to login from different part of the world).

To resolve I had to: (first time)

  • login to my account via web
  • view recent attempts to use the account and accept suspicious access: THIS LINK
  • disable the feature of blocking suspicious apps/technologies: THIS LINK

This worked the first time, but few hours later, probably because I was doing a lot of testing the problem reappeared and was not fixable using the above method. In addition I had to clear the captcha (the funny picture, which asks you to rewrite a word or a sentence when logging into any account nowadays too many times) :

  • after login to my account I went HERE
  • Clicked continue

Hope this helps.

like image 64
callmebob Avatar answered Sep 22 '22 03:09

callmebob


Use this:

https://www.google.com/settings/u/1/security/lesssecureapps https://accounts.google.com/b/0/DisplayUnlockCaptcha https://security.google.com/settings/security/activity?hl=en&pli=1 

this link allow acces to google account

UPDATE 19-05-2017:

These url you must to visit from the IP address that will be send email

like image 41
Sanya Snex Avatar answered Sep 23 '22 03:09

Sanya Snex