php - Google SMTP Error: Could not authenticate -


the following code not work once put on server, have similar code working on local environment , works perfectly, ideas?

edit: did set gmail setting "less secure"

<?php $setid = $_post['setid']; $promo = $_post['promo'];   echo "good sir, set id ".$setid.", , eligible following deal:"; echo "<br><br>"; echo $promo;  $message=  "good sir, set id ".$setid.", , eligible following deal:"."<br><br>".$promo;      require "phpmailer/class.phpmailer.php";      // instantiate class       $mail = new phpmailer();      // set smtp       $mail->issmtp();                    $mail->smtpauth = true;              $mail->smtpsecure = "ssl";      $mail->host = "smtp.gmail.com";      $mail->port = 465;      $mail->encoding = '7bit';      // authentication       $mail->username   = "xxx@example.com";     $mail->password   = "mypass";      // compose     $mail->setfrom("jghh@ghh.ca");     $mail->addreplyto("ghh@ghh.ca");     $mail->subject = "tryit";     $mail->msghtml($message);      // send       $mail->addaddress("receiver@hotmail.com", "recipient name");     $result = $mail->send();     $message = $result ? 'successfully sent!' : 'sending failed!';           unset($mail);    ?> 

this in network -> preview:

good sir, set id 100065, , eligible following deal:

current promotion: enjoy 15% discount on next visit!smtp error: not authenticate.

you need enable less secure apps


change account access less secure apps

to keep google apps users' accounts secure, may block less secure apps accessing google apps accounts. google apps user, see "password incorrect" error when trying sign in. if case, have 2 options:

  1. option 1: upgrade more secure app uses date security measures. google products, gmail, use latest security measures.
  2. option 2: change settings allow less secure apps access account. don't recommend option because might make easier break account. if want allow access anyway, follow these steps:

    2.1. go "less secure apps" section in account

    2.2. next "access less secure apps," select turn on. (note google apps users: setting hidden if administrator has locked less secure app account access.)

if still can't sign in account, "password incorrect" error might caused different reason.

src: https://support.google.com/accounts/answer/6010255?hl=en


update:

add error reporting top of file(s) right after opening php tag example <?php error_reporting(e_all); ini_set('display_errors', 1);

and enable debug on phpmailer

$mail->smtpdebug  = 1; // enables smtp debug information (for testing)                        // 1 = errors , messages                        // 2 = messages 

to see if yields anything.


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -