title: SMTP: Failed to connect socket: Connection Refused
body: <p>I'm trying to send an email in PHP using PEAR Mail package and SMTP, but I keep getting the error <code>SMTP: Failed to connect socket: Connection Refused</code></p>
  
  <p>I don't really know anything about how SMTP works, so bear with me.</p>
  
  <p><strong>Here is my code:</strong></p>
  
  <pre><code>$recipients = $_SESSION['email'];
  $headers["From"] = "example@example.com";
  $headers["To"] = "example@example.com";
  $headers["Subject"] = 'Subject Text!';
  $mailmsg = $_SESSION['body'];
  
  /* SMTP server name, port, user/password */
  $smtpinfo["host"] = "mail.example.com";
  $smtpinfo["port"] = "587";
  $smtpinfo["auth"] = true;
  $smtpinfo["username"] = $email_user;
  $smtpinfo["password"] = $email_pass;
  /* Create the mail object using the Mail::factory method */
  $mail_object =&amp; Mail::factory("smtp", $smtpinfo);
  /* Ok send mail */
  $send = $mail_object-&gt;send($recipients, $headers, $mailmsg);
  if (PEAR::isError($send)) {
      echo '&lt;p&gt;Error: ' . $send-&gt;getMessage() . '&lt;/p&gt;';
  } else {
      header('Location: ../../emailed.php');
  }
  </code></pre>
  
  <p><strong>What I know is:</strong></p>
  
  <p>Domain is hostgator, and the email handler is Keiro Connect.</p>
  
  <p>I'm not sure which port to go through. I looked at the services, and it says that the Listening IP Addresses are:</p>
  
  <ul>
  <li>SMTP: All addresses:25, All addresses:587</li>
  <li>Secure SMTP: All addresses:465</li>
  <li>SMTP Submission: All addresses:587 *<em>this service is turned off though</em></li>
  </ul>
  
  <p>I've also noted that SMTP delivery is set to deliver directly using DNS MX records. I don't know if that means anything.</p>
  
  <p>What am I doing wrong? What should I be looking for so I can get all the parameters in order?
  Any help would be greatly appreciated.</p>