title: Connection Refused using PHPMailer with Namecheap Accounts
body: <p>I have been using the code below to try to send emails out to people who sign up on my website however I can not get the code to work with my namecheap hosted email account. This <a href="https://www.namecheap.com/support/knowledgebase/article.aspx/1179/2175/general-configuration-for-mail-clients-and-mobile-devices" rel="nofollow">namecheap email configuration</a> was used but it seems to still give me an error. I have tried the same code with the hotmail settings and it works just fine. </p>
  
  <p><strong>Error</strong></p>
  
  <pre><code>2016-06-17 09:28:33 SMTP ERROR: Failed to connect to server: Connection refused (61) 2016-06-17 09:28:33    SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting Mailer: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
  </code></pre>
  
  <p><strong>Code</strong></p>
  
  <pre><code>require_once('PHPMailerAutoload.php');
      function sendmail($host, $username, $password, $to, $subject, $message, $fromName, $toName, $port, $debug) {
          $mail = new PHPMailer();
          $body = $message;
          $mail-&gt;IsSMTP();
          $mail-&gt;Host = $host;
          if ($debug) $mail-&gt;SMTPDebug = 2;
          $mail-&gt;SMTPAuth = true;
          $mail-&gt;SMTPSecure = "tls"; 
          $mail-&gt;Port = $port;
          $mail-&gt;Username = $username;
          $mail-&gt;Password = $password;
          $mail-&gt;SetFrom($to, $name);
          $mail-&gt;AddReplyTo($to, $name);
          $mail-&gt;Subject = $subject;
          $mail-&gt;AltBody = $message;
          $mail-&gt;MsgHTML($body);
  
          $address = $to;
          $mail-&gt;AddAddress($address, $name);
          if($mail-&gt;Send()) {
              echo "Message sent";
          } else {
              echo "Mailer: " . $mail-&gt;ErrorInfo;
          }
      }
  
  echo sendMail("mail.privateemail.com", "noreply@example.com", "password", "recipient@example.com", "Subject", "Message", "Name", "Sender Name", 25, true);
  </code></pre>