title: Read email with IMAP and PHP - Connection Refused
body: <p>I want to read a mail's inbox using PHP IMAP.</p>
  
  <p>On phpinfo() i see both <em>OpenSSL</em> and <em>IMAP</em> enabled.</p>
  
  <p>When trying to connect:</p>
  
  <pre><code>/* connect to inbox */
  $hostname = "{imap-mail.outlook.com:993/imap/tls}INBOX";
  $username = 'mail@...';
  $password = 'password';
  
  /* try to connect */
  $inbox = imap_open($hostname,$username,$password) or die('Error: ' . imap_last_error());
  </code></pre>
  
  <p>It will always throw an error:</p>
  
  <p><em>Can't connect to imap.glbdns2.microsoft.com,993: Connection refused (errflg=2)</em></p>
  
  <p>On the outlook settings it says:</p>
  
  <p><a href="https://i.stack.imgur.com/26zEW.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/26zEW.jpg" alt="enter image description here"></a></p>
  
  <p>Why does this happen and how can I fix it?</p>