title: SMTP ERROR: Failed to connect to server: Connection refused (111) with Office365
body: <p>Sorry if this is a road heavily traveled. I've seen the other posts about this but nothing in them has either solved the problem I'm having or ignited a lightbulb that helped me solve it myself.</p>
  
  <p>Here's my code:</p>
  
  <pre><code>require 'PHPMailerAutoload.php';
  $config = parse_ini_file('/path/to/file/config.ini', true);
  $mail = new PHPMailer;
  $mail-&gt;SMTPDebug = 3;
  $mail-&gt;Debugoutput = 'html';
  $mail-&gt;isSMTP();
  $mail-&gt;Host = $config['host']; //smtp.office365.com
  $mail-&gt;SMTPAuth = true;
  $mail-&gt;Username = $config['username']; //an.existing.account@appinc.co
  $mail-&gt;Password = $config['password']; //confirmed this is being passed correctly
  $mail-&gt;SMTPSecure = 'tls';
  $mail-&gt;Port = 587;
  $mail-&gt;From = $config['username'];
  $mail-&gt;FromName = 'Website Forms';
  $mail-&gt;addAddress('sales@appinc.co', 'Some Name');
  $mail-&gt;addReplyTo('sender.email@somedomain.com', 'SenderFirst SenderLast');
  $mail-&gt;addBCC('my.email.address@appinc.co');
  $mail-&gt;isHTML(true);
  $mail-&gt;Subject = 'Contact Form Submission';
  $mail-&gt;Body = 'Some html here';
  $mail-&gt;AltBody = 'Some alt content here';
  if(!$mail-&gt;send()) {
      echo 'Mailer Error: ' . $mail-&gt;ErrorInfo;
  } else {
      //perform success actions
      exit();
  }
  </code></pre>
  
  <p>I've confirmed that the domain, username and password are all correct and being passed in correctly. Important to note that this worked on our local dev server prior to launch. Once the site was moved to our hosting account (Hostgator) is when it stopped working. I've confirmed with HG that port 587 is open on our server.</p>
  
  <p>Here is the error message I'm seeing:</p>
  
  <pre><code>Connection: opening to smtp.office365.com:587, t=10, opt=array ()
  SMTP ERROR: Failed to connect to server: Connection refused (111)
  SMTP connect() failed.
  Message could not be sent.Mailer Error: SMTP connect() failed.
  </code></pre>
  
  <p>Any help that can be provided is very much appreciated, even if it's just a link to an article that explains why it won't work now that it's in our production environment.</p>