title: 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?
body: <p>I would like to send an email using <strong>Gmail SMTP</strong> server through <strong>PHP Mailer</strong>.</p>
  
  <p>this is my code</p>
  
  <pre><code>&lt;?php
  require_once('class.phpmailer.php');
  
  $mail = new PHPMailer();
  $mail-&gt;IsSMTP();
  $mail-&gt;CharSet="UTF-8";
  $mail-&gt;SMTPSecure = 'tls';
  $mail-&gt;Host = 'smtp.gmail.com';
  $mail-&gt;Port = 587;
  $mail-&gt;Username = 'MyUsername@gmail.com';
  $mail-&gt;Password = 'valid password';
  $mail-&gt;SMTPAuth = true;
  
  $mail-&gt;From = 'MyUsername@gmail.com';
  $mail-&gt;FromName = 'Mohammad Masoudian';
  $mail-&gt;AddAddress('anotherValidGmail@gmail.com');
  $mail-&gt;AddReplyTo('phoenixd110@gmail.com', 'Information');
  
  $mail-&gt;IsHTML(true);
  $mail-&gt;Subject    = "PHPMailer Test Subject via Sendmail, basic";
  $mail-&gt;AltBody    = "To view the message, please use an HTML compatible email viewer!";
  $mail-&gt;Body    = "Hello";
  
  if(!$mail-&gt;Send())
  {
    echo "Mailer Error: " . $mail-&gt;ErrorInfo;
  }
  else
  {
    echo "Message sent!";
  }
  ?&gt;
  </code></pre>
  
  <p>but I receive this following error</p>
  
  <pre><code>Mailer Error: SMTP Error: The following recipients failed: anotherValidGmail@gmail.com
  
  SMTP server error: SMTP AUTH is required for message submission on port 587
  </code></pre>
  
  <p>my domain is <a href="http://www.vatandesign.ir" rel="noreferrer">vatandesign.ir</a></p>