title: PEAR Mail connection refused to smtp.gmail.com
body: <p>I'm having endless trouble while trying to send mail using the pear mail package:</p>
  
  <p>I'm using xampp on my local machine for testing purposes and the following code works perfectly:</p>
  
  <pre><code>//PEAR
  
      require_once('../PEAR/Mail.php');
  
  
      $from = "&lt;sender@domain.com&gt;";
      $to = "&lt;receiver@domain.com&gt;";
      $subject = "Hi";
      $body = "Testing message";
  
      $host = "ssl://smtp.gmail.com"; //ssl://
      $port = "465";
      $username = "my_account@gmail.com";
      $password = "**********";
  
      $headers = array ('From' =&gt; $from,
        'To' =&gt; $to,
        'Subject' =&gt; $subject);
      $smtp = Mail::factory('smtp',
        array ('host' =&gt; $host,
          'port' =&gt; $port,
          'auth' =&gt; true,
          'username' =&gt; $username,
          'password' =&gt; $password));
  
      $mail = $smtp-&gt;send($to, $headers, $body);
  
      function &amp;factory($driver, $params = array())
  {
      $driver = strtolower($driver);
      @include_once 'Mail/' . $driver . '.php';
      $class = 'Mail_' . $driver;
      if (class_exists($class)) {
          $mailer = new $class($params);
          return $mailer;
      } else {
          return PEAR::raiseError('Unable to find class for driver ' . $driver);
      }
  }
  
  
     if (PEAR::isError($mail)) {
        echo("&lt;p&gt;" . $mail-&gt;getMessage() . "&lt;/p&gt;");
       } else {
        echo("&lt;p&gt;Message successfully sent!&lt;/p&gt;");
       }
  
      //end of php tag
  </code></pre>
  
  <p>HOWEVER, when I upload the file to the online web server and run the exact same script I receive the following error:</p>
  
  <p>"Failed to connect to ssl://smtp.gmail.com:465 [SMTP: Failed to connect socket: Connection refused (code: -1, response: )]"</p>
  
  <p>I have also tried ports 587 and 443 to no avail. I'm guessing the problem must lie with either socket.php, smtp.php, mail.php or even with the server config files since there seems to be nothing wrong with the above code. I would be extremely grateful if someone could point me in the right direction!</p>