title: How to configure gmail smtp and phpmailer?
body: <p>I want to know where the problem is because I get authentication error.</p>
  
  <ol>
  <li>I already have a few gmail accounts, </li>
  <li>I created a new one for my website,</li>
  <li>I added a new email in "Account and import" to my old gmail account.</li>
  <li>I copied my new email username and password to phpmailer code</li>
  </ol>
  
  <blockquote>
  <pre><code>include_once('phpmailer/class.phpmailer.php');
  include_once('phpmailer/class.smtp.php');
  //6nb5Drv;
  function sendmail(){
  $mail = new PHPMailer();  
  
  $mail-&gt;IsSMTP();                                      // set mailer to use SMTP
  $mail-&gt;SMTPAuth = true;     // turn on SMTP authentication
  $mail-&gt;SMTPSecure = "tls";
  $mail-&gt;Host = "smtp.gmail.com";  // specify main and backup server
  $mail-&gt;Port = 587; // Set the SMTP port i tried and 457
  $mail-&gt;Username = 'newmail@gmail.com';                // SMTP username
  $mail-&gt;Password = 'newmailpass';                  // SMTP password
  
  $mail-&gt;SMTPDebug  = 1;                     // enables SMTP debug information (for testing)
                                             // 1 = errors and messages
                                             // 2 = messages only
  
  $mail-&gt;From = 'from@yahoo.com';
  $mail-&gt;FromName = 'From';
  $mail-&gt;AddAddress('to@gmail.com', 'To');  // Add a recipient
  
  $mail-&gt;IsHTML(true);                                  // Set email format to HTML
  
  $mail-&gt;Subject = 'Here is the subject';
  $mail-&gt;Body    = 'This is the HTML message body &lt;strong&gt;in bold!&lt;/strong&gt;';
  $mail-&gt;AltBody = 'This is the body in plain text for non-HTML mail clients';
  
  if(!$mail-&gt;Send()) {
     echo 'Message could not be sent.';
     echo 'Mailer Error: ' . $mail-&gt;ErrorInfo;
     exit;
  }
  
  echo 'Message has been sent';
  }
  sendmail();
  </code></pre>
  </blockquote>
  
  <p>But I get an authentication error.
  What is wrong? 
  Probably something with the credentials, how do I configure gmail smtp?</p>
  
  <p>Debug report:</p>
  
  <blockquote>
    <p>2015-12-04 17:56:15   CLIENT -> SERVER: EHLO www.site.co
    2015-12-04 17:56:15   CLIENT -> SERVER: STARTTLS 2015-12-04
    17:56:15  CLIENT -> SERVER: EHLO www.site.co 2015-12-04
    17:56:15  CLIENT -> SERVER: AUTH LOGIN 2015-12-04 17:56:15    CLIENT ->
    SERVER: UHJlZGljdG9sb2d5 2015-12-04 17:56:15  CLIENT -> SERVER:
    U2dHZlB0VHZUbTZ1SW9ZMi1qTlNCQQ== 2015-12-04 17:56:17  SMTP ERROR:
    Password command failed: 435 4.7.8 Error: authentication failed:
    UGFzc3dvcmQ6 2015-12-04 17:56:17  SMTP Error: Could not authenticate.
    2015-12-04 17:56:17   CLIENT -> SERVER: QUIT 2015-12-04 17:56:17  SMTP
    connect() failed.
    <a href="https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting" rel="nofollow">https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting</a> Message
    could not be sent.Mailer Error: SMTP connect() failed.
    <a href="https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting" rel="nofollow">https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting</a></p>
  </blockquote>