title: Could not connect to SMTP host. Mailer Error: SMTP Error: Could not connect to SMTP host
body: <p>I'm using <code>PHPMailer</code> for sending mail with authentication, but i'm getting the following message when i tried to run my <strong>sendmessage.php.</strong></p>
  
  <pre><code>SMTP -&gt; ERROR: Failed to connect to server: Connection timed out (110) 
  SMTP Error: Could not connect to SMTP host. Mailer Error: SMTP Error: Could not connect to SMTP host.
  </code></pre>
  
  <p>can anyone please tell me why i'm getting this message...and some solution for this</p>
  
  <p>Mycode is as given below</p>
  
  <p><strong>sendmessage.php</strong></p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
  &lt;title&gt;PHPMailer - SMTP (Gmail) basic test&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  
  &lt;?php
  
  //error_reporting(E_ALL);
  error_reporting(E_STRICT);
  
  date_default_timezone_set('America/Toronto');
  
  require_once('../class.phpmailer.php');
  //include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded
  
  
  $mail = new PHPMailer(); // create a new object
  $mail-&gt;IsSMTP(); // enable SMTP
  $mail-&gt;SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only
  $mail-&gt;SMTPAuth = true; // authentication enabled
  $mail-&gt;SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for GMail
  $mail-&gt;Host = "smtp.gmail.com";
  $mail-&gt;Port = 465; // or 587
  $mail-&gt;IsHTML(true);
  $mail-&gt;Username = "myemailid@gmail.com";
  $mail-&gt;Password = "myemailpassword";
  $mail-&gt;SetFrom('myemailid@gmail.com','vgvb');
  $mail-&gt;Subject = "Test";
  $mail-&gt;Body = "hello";
  $mail-&gt;AddAddress('myfriendemailid');
   if(!$mail-&gt;Send())
      {
      echo "Mailer Error: " . $mail-&gt;ErrorInfo;
      }
      else
      {
      echo "Message has been sent";
      }
  ?&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>