title: “SMTP Error Could not connect to SMTP host. Message was not sent
body: <p>I am working on a webmail in which i am using phpmailer class .The problem is i am getting the error  "SMTP Error: Could not connect to SMTP host. Message was not sent 
  PHP Mailer Error: SMTP Error: Could not connect to SMTP host."</p>
  
  <p>my code is :</p>
  
  <p></p>
  
  <pre><code> &lt;html&gt;
  &lt;head&gt;
  &lt;title&gt;PHPMailer - SMTP basic test with authentication&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();
  
  $body             = file_get_contents('contents.html');
  $body             = eregi_replace("[\]",'',$body);
  
  $mail-&gt;IsSMTP();
  $mail-&gt;Port = 465;
  $mail-&gt;Host = 'smtp.gmail.com'; // "ssl://smtp.gmail.com" didn't worked
  $mail-&gt;IsHTML(true); // if you are going to send HTML formatted emails
  $mail-&gt;Mailer = 'smtp';
  $mail-&gt;SMTPSecure = 'ssl';
  
  $mail-&gt;SMTPAuth = true;
  $mail-&gt;Username = "email@gmail.com";
  $mail-&gt;Password = "mypass";
  
  $mail-&gt;SingleTo = true; // if you want to send mail to the users individually so that no recipients can see that who has got the same email.
  
  $mail-&gt;From = "email@gmail.com";
  $mail-&gt;FromName = "mypass";
  
  $mail-&gt;addAddress("livelyphoneix@yahoo.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 PHP Mailer 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;PHP Mailer Error: " . $mail-&gt;ErrorInfo;
  else
      echo "Message has been sent";
  
  ?&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  
  And my php.ini setting is :
  
      [mail function]
  ; For Win32 only.
  ; http://php.net/smtp
  ;SMTP =
  ; http://php.net/smtp-port
  ;smtp_port = 465
  
  ; For Win32 only.
  ; http://php.net/sendmail-from
  ;sendmail_from = you@domain.com
  ; For Unix only.  You may supply arguments as well (default: "sendmail -t -i").
  ; http://php.net/sendmail-path
  sendmail_path ="C:\wamp\sendmail\sendmail.exe -t -i"
  
  ; Force the addition of the specified parameters to be passed as extra parameters
  ; to the sendmail binary. These parameters will always replace the value of
  ; the 5th parameter to mail(), even in safe mode.
  ;
  </code></pre>
  
  <p>would someone like to let me know that where i am wrong , I need your kind attention at this problem.</p>