title: Message was not sent PHPMailer Error: SMTP connect() failed Error
body: <pre><code>&lt;?php
  
  require 'PHPMailerAutoload.php';
  $mail = new PHPMailer();
  $mail-&gt;IsSMTP();
  $mail-&gt;Mailer = 'smtp';
  $mail-&gt;SMTPAuth = true;
  $mail-&gt;Host = 'smtp.gmail.com'; // "ssl://smtp.gmail.com" didn't worked
  $mail-&gt;Port = 465;
  $mail-&gt;SMTPSecure = 'ssl';
  // or try these settings (worked on XAMPP and WAMP):
  // $mail-&gt;Port = 587;
  // $mail-&gt;SMTPSecure = 'tls';
  
  
  $mail-&gt;Username = "vignesh*****@gmail.com";
  $mail-&gt;Password = "**********";
  
  $mail-&gt;IsHTML(true); // if you are going to send HTML formatted emails
  $mail-&gt;SingleTo = true; // if you want to send a same email to multiple users. multiple emails will be sent one-by-one.
  
  $mail-&gt;From = "vignesh*******@gmail.com";
  $mail-&gt;FromName = "vignesh";
  
  $mail-&gt;addAddress("vigneshanandakumar@gmail.com","User 1");
  /*$mail-&gt;addAddress("user.2@gmail.com","User 2");
  
  $mail-&gt;addCC("user.3@ymail.com","User 3");
  $mail-&gt;addBCC("user.4@in.com","User 4");*/
  
  $mail-&gt;Subject = "Testing PHPMailer with localhost";
  $mail-&gt;Body = "Hi,&lt;br /&gt;&lt;br /&gt;This system is working perfectly.";
  
  if(!$mail-&gt;Send())
      echo "Message was not sent &lt;br /&gt;PHPMailer Error: " . $mail-&gt;ErrorInfo;
  else
      echo "Message has been sent";
      ?&gt;
  </code></pre>
  
  <p>I get the </p>
  
  <blockquote>
    <p>Message was not sent 
    <br>PHPMailer Error: SMTP connect() failed</p>
  </blockquote>
  
  <p>when I try to run the PHP file. Please help me resolve the error. What could be the possible wrong things I've done to get the error and how to resolve this?</p>