title: SMTP Error: Could not authenticate. Message could not be sent. Mailer Error: SMTP Error: Could not authenticate
body: <p>When I trying to send a email using PHP SMTP email server, following error has occurred.</p>
  
  <pre><code>SMTP Error: Could not authenticate. Message could not be sent.
  </code></pre>
  
  <p>Mailer Error: SMTP Error: Could not authenticate.</p>
  
  <hr>
  
  <p>Following is my code that I have used.</p>
  
  <pre><code>function supervisorMail(){
  
  global $error;
  $mail = new PHPMailer();
  $mail-&gt;IsSMTP();
  $mail-&gt;SMTPDebug = 0;
  $mail-&gt;SMTPAuth = true;
  $mail-&gt;SMTPSecure = 'ssl';
  $mail-&gt;Host = 'smtp.gmail.com';
  $mail-&gt;Port = 465;
  $mail-&gt;Username = "***@gmail.com";
  $mail-&gt;Password = "****";
  $mail-&gt;SetFrom("***@gmail.com", "Employee Leave Management System");
  
  $userID=$_SESSION['userID'];
  
  $select_query = mysql_query("SELECT * FROM employee WHERE emp_id = '$userID'");
  $select_sql = mysql_fetch_array($select_query);
  $name=$select_sql['manager_name'];
  var_dump($name);
  
  $select_query1 = mysql_query("SELECT email FROM employee WHERE emp_id='$name'");
  $select_sql1 = mysql_fetch_array($select_query1);
  $email=$select_sql1['email'];
      var_dump($email);
  
  $mail-&gt;Subject = "subject ";
  $mail-&gt;Body = "something.";
  $mail_to = $email;
  $mail-&gt;AddAddress($mail_to);
  
  if(!$mail-&gt;Send())
  {
      echo "Message could not be sent. &lt;p&gt;";
      echo "Mailer Error: " . $mail-&gt;ErrorInfo;
      exit;
  }
  
  echo "Message has been sent";
  </code></pre>
  
  <p>}</p>
  
  <p>How can I fixed this error.</p>