title: PHPMailer SMTP Gmail authentification error
body: <p>I'm sending emails using PHPMailer 5.2.10 with the next code:</p>
  <pre><code>function SendGmail($to,$subj,$body)
  {
      $mail = new PHPMailer(); // create a new object
      $mail-&gt;IsSMTP(); // enable SMTP
      $mail-&gt;SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only
      $mail-&gt;SMTPAuth = true; // authentication enabled
      $mail-&gt;SMTPSecure = 'ssl'; // &quot;ssl&quot; secure transfer enabled REQUIRED for GMail
      $mail-&gt;Host = &quot;smtp.gmail.com&quot;;
      $mail-&gt;Port = 465; // 465 or 587
      $mail-&gt;IsHTML(true);
      $mail-&gt;Username = &quot;admin@mydomain.ru&quot;;
      $mail-&gt;Password = &quot;********&quot;;
      $mail-&gt;SetFrom(&quot;admin@mydomain.ru&quot;);
      $mail-&gt;Subject = $subj;
      $mail-&gt;Body = $body;
      $mail-&gt;AddAddress($to);
      return $mail-&gt;Send();
  }
  </code></pre>
  <p>Note: we use Google Apps, so the mail domain is not google.com, but some other, let's say, mydomain.ru.</p>
  <p><strong>Everything was fine until Google had recently implemented another &quot;security enhancement&quot;</strong> <em>(AFAIK forcing OAuth2 authorisation)</em>. Now PHPMailer-&gt;Send() returns the following text:</p>
  <pre><code>2015-05-12 06:49:15 CLIENT -&gt; SERVER: EHLO 127.0.0.1 
  2015-05-12 06:49:15 CLIENT -&gt; SERVER: AUTH LOGIN 
  2015-05-12 06:49:15 CLIENT -&gt; SERVER: [some base64 string] 
  2015-05-12 06:49:15 CLIENT -&gt; SERVER: [some base64 string] 
  2015-05-12 06:49:16 SMTP ERROR: Password command failed: 535-5.7.8 Username and Password not accepted. Learn more at 535 5.7.8 http://support.google.com/mail/bin/answer.py?answer=14257 u10sm3566045lbb.30 - gsmtp 
  2015-05-12 06:49:16 SMTP Error: Could not authenticate. 
  2015-05-12 06:49:16 CLIENT -&gt; SERVER: QUIT 
  2015-05-12 06:49:16 SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting bool(false) Done!
  </code></pre>
  <p>Ok, I go to <a href="http://support.google.com/mail/bin/answer.py?answer=14257" rel="nofollow noreferrer">http://support.google.com/mail/bin/answer.py?answer=14257</a> and doing the following:</p>
  <ul>
  <li><p>Logging to this account via web interface - everything's Ok,</p>
  </li>
  <li><p>Opening this link in browser: <a href="http://www.google.com/accounts/DisplayUnlockCaptcha" rel="nofollow noreferrer">http://www.google.com/accounts/DisplayUnlockCaptcha</a> - google says everything is Ok,</p>
  </li>
  <li><p>Opening this link: <a href="https://support.google.com/accounts/answer/6010255" rel="nofollow noreferrer">https://support.google.com/accounts/answer/6010255</a> and then this link: <a href="https://www.google.com/settings/security/lesssecureapps" rel="nofollow noreferrer">https://www.google.com/settings/security/lesssecureapps</a> where I see the following:</p>
  </li>
  </ul>
  <blockquote>
  <p>&quot;<strong>Access for less secure apps</strong>: * Turn off / * Turn on&quot; - for normal gmail account,</p>
  <p><strong>(&quot;This setting is inaccessible for google apps accounts&quot;) - for google apps account</strong> (not the exact text but my translation from russian as google shows it).</p>
  </blockquote>
  <p><strong>Yes, I have tried both SSL and TLS, 485 or 587 ports and everything else I've found on stackoverflow.com and here:</strong> <a href="https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting" rel="nofollow noreferrer">https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting</a> . Nothing helped.</p>
  <p>PHPMailer troubleshooting page suggests to use &quot;an OAuth2 client class&quot;: <a href="http://www.phpclasses.org/package/7700-PHP-Authorize-and-access-APIs-using-OAuth.html" rel="nofollow noreferrer">http://www.phpclasses.org/package/7700-PHP-Authorize-and-access-APIs-using-OAuth.html</a> - but I have no idea of how to integrate it into PHPMailer and why it's not integrated yet by PHPMailer developers (this class is under BSD license), while it's necessary now for one of the most popular mail servers. I found no documentation for this OAuth2 about integrating it into PHPMailer, and I'm sure I can't do it myself - my PHP knowledge is poor.</p>
  <p>The question is:</p>
  <ol>
  <li><p>How can I avoid this goddamn OAuth2 and send emails as I did it before this &quot;security enhancement&quot; (<strong>for google apps account</strong>)?   <strong>--OR:</strong></p>
  </li>
  <li><p>How to easily integrate OAuth2 class mentioned above into PHPMailer?    <strong>--OR:</strong></p>
  </li>
  <li><p>Are there any other easy-to-use PHP solutions to send emails using gmail?</p>
  </li>
  </ol>
  <p>Lots of thanks in advance.</p>