title: Having trouble with PHPMailer
body: <p>I am trying to use PHPMailer to send a gmail email. I followed this <a href="https://stackoverflow.com/questions/4982821/send-email-from-localhost-with-gmailwindows">post</a></p>
  
  <p>In order to do this, I set up a function shown below:  </p>
  
  <pre><code>function sendEmail($email, $name) {
      $mail = new PHPMailer();
      $mail-&gt;IsSMTP(); // send via SMTP
      //IsSMTP(); // send via SMTP I commented it cos it gives an error
      $mail-&gt;SMTPAuth = true; // turn on SMTP authentication
      $mail-&gt;Username = 'email@gmail.com'; // Changed my email
      $mail-&gt;Password = "password";// Changed my password
      $mail-&gt;From = 'email@gmail.com';
      $mail-&gt;FromName = 'FROM NAME';
  
  
      $mail-&gt;AddAddress($email);
  
      $mail-&gt;IsHTML(true); // send as HTML
      $mail-&gt;Subject = "Subject";
      $mail-&gt;Body = "Body";
  
      if (!$mail-&gt;Send()) {
          return false;
      } else {
          return true;
      }
  }
  </code></pre>
  
  <p><strong>Unfortunately, it keeps on returning false. Can you please tell me whats wrong with the code?</strong></p>
  
  <p>Edit: The error which I am getting is shown below:</p>
  
  <pre><code>SMTP -&gt; ERROR: Failed to connect to server: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
  
  SMTP Error: Could not connect to SMTP host.
  </code></pre>
  
  <p>UPDATED CODE:</p>
  
  <pre><code> $Mail = new PHPMailer();
      $Mail-&gt;IsSMTP(); // Use SMTP
      $Mail-&gt;Host = "smtp.gmail.com"; // Sets SMTP server
      $Mail-&gt;SMTPDebug = 2; // 2 to enable SMTP debug information 
      $Mail-&gt;SMTPAuth = TRUE; // enable SMTP authentication
      $Mail-&gt;SMTPSecure = "tls"; //Secure conection
      $Mail-&gt;Port = 587; // set the SMTP port
      $Mail-&gt;Username = EMAIL; // SMTP account username
      $Mail-&gt;Password = PASS; // SMTP account password
      $Mail-&gt;Priority = 1; // Highest priority - Email priority (1 = High, 3 = Normal, 5 = low)
      $Mail-&gt;CharSet = 'UTF-8';
      $Mail-&gt;Encoding = '8bit';
      $Mail-&gt;Subject = 'SUB';
      $Mail-&gt;ContentType = 'text/html; charset=utf-8\r\n';
      $Mail-&gt;From = EMAIL;
      $Mail-&gt;FromName = 'FROM NAME';
      $Mail-&gt;WordWrap = 900; // RFC 2822 Compliant for Max 998 characters per line
  
      $Mail-&gt;AddAddress($email); // To:
      $Mail-&gt;isHTML(TRUE);
      $Mail-&gt;Body = "Hi";
      $Mail-&gt;AltBody = "Hi";
      $Mail-&gt;Send();
      $Mail-&gt;SmtpClose();
  </code></pre>