title: Error in send email by smtp use PEAR Mail package in php
body: <p>I am using this code to send message by SMTP and have below error:
  <br>What is the problem?
  <br>
  My IMAP is on and username and password are correct and apps access to gmail is on</p>
  
  <pre><code>&lt;?php
  include 'Mail.php';
  include 'Mail/mime.php' ;
  
  $from = "Robert Davis &lt;mymail@gmail.com&gt;";
  $to = "Sam Hill &lt;receiver&gt;";
  $subject = 'Test mime message with an attachment';
  
  $headers = array ('From' =&gt; $from,'To' =&gt; $to, 'Subject' =&gt; $subject);
  
  $text = 'Text version of email';// text and html versions of email.
  $html = '&lt;html&gt;&lt;body&gt;HTML version of email. &lt;strong&gt;This should be bold&lt;/strong&gt;&lt;/body&gt;        &lt;/html&gt;';
  
  $file = './sample.txt'; // attachment
  $crlf = "\n";
  
  $mime = new Mail_mime($crlf);
  $mime-&gt;setTXTBody($text);
  $mime-&gt;setHTMLBody($html);
  $mime-&gt;addAttachment($file, 'text/plain');
  
  //do not ever try to call these lines in reverse order
  $body = $mime-&gt;get();
  $headers = $mime-&gt;headers($headers);
  
  $host = "smtp.gmail.com";
  $username = "mymail";
  $password = "mypass";
  
  $smtp = Mail::factory('smtp', array ('host' =&gt; $host, 'auth' =&gt; true  'username' =&gt; $username,'password' =&gt; $password));
  
  $mail = $smtp-&gt;send($to, $headers, $body);
  
  if (PEAR::isError($mail)) {
    echo("&lt;p&gt;" . $mail-&gt;getMessage() . "&lt;/p&gt;");
  }
  else {
    echo("&lt;p&gt;Message successfully sent!&lt;/p&gt;");
  }
  
  ?&gt;
  </code></pre>
  
  <p>This is error that i see:</p>
  
  <p>authentication failure [SMTP: Invalid response code received from server (code: 534, response: 5.7.14 Please log in via your web browser and 5.7.14 then try again. 5.7.14 Learn more at 5.7.14 <a href="https://support.google.com/mail/answer/78754" rel="nofollow noreferrer">https://support.google.com/mail/answer/78754</a> x67sm2291331iod.22 - gsmtp)]</p>