Unable to send email using Gmail SMTP server through PHPMailer, getting error: SMTP AUTH is required for message submission on port 587. How to fix?

前端 未结 12 2419
[愿得一人]
[愿得一人] 2020-11-22 02:42

I would like to send an email using Gmail SMTP server through PHP Mailer.

this is my code



        
12条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-22 03:35

    Anderscc has got it correct. Thanks. It worked for me but not 100%.

    I had to set

    $mail->SMTPDebug = 0;
    

    Setting it to 1, can cause errors especially if you are passing some data as json to next page. Example - Performing verification if mail is sent, using json to pass data through ajax.

    I had to lower my gmail account security settings to get rid of errors: " SMTP connect() failed " and " SMTP ERROR: Password command failed "

    Solution: 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).

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

    • view recent attempts to use the account and accept suspicious access.

    • link to disable the feature of blocking suspicious apps/technologies:

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

    Note: You can go to the following stackoverflow answer link for more detailed reference.

    https://stackoverflow.com/a/25175234

提交回复
热议问题