title: fsockopen ssl connection not working
body: <p>I'm trying to use php function fsockopen on a smtp server using ssl on port 465 on my local server with apache.
  It works well with php command line but I get a SSL error when the script is running in my browser.</p>
  
  <p>php.ini</p>
  
  <pre class="lang-none prettyprint-override"><code>extension=php_openssl.dll line is not commented
  </code></pre>
  
  <p>phpinfo through Apache</p>
  
  <pre class="lang-none prettyprint-override"><code>Loaded Configuration File : D:\localhost\php-5.4.11\php.ini
  openssl
  OpenSSL support enabled
  OpenSSL Library Version OpenSSL 0.9.8x 10 May 2012
  OpenSSL Header Version  OpenSSL 0.9.8x 10 May 2012
  </code></pre>
  
  <p>phpinfo with command line</p>
  
  <pre class="lang-none prettyprint-override"><code>Loaded Configuration File =&gt; D:\localhost\php-5.4.11\php.ini
  openssl
  OpenSSL support =&gt; enabled
  OpenSSL Library Version =&gt; OpenSSL 0.9.8x 10 May 2012
  OpenSSL Header Version =&gt; OpenSSL 0.9.8x 10 May 2012
  </code></pre>
  
  <p>My script</p>
  
  <pre class="lang-php prettyprint-override"><code>$smtp = fsockopen('ssl://in.mailjet.com', 465, $errno, $errstr, 30);
  $response = fgets($smtp, 4096);
  if(empty($smtp)){
     echo $response;
     return false;
  }
  echo $response . '&lt;br/&gt;';
  fclose($smtp);
  </code></pre>
  
  <p>Output under apache</p>
  
  <pre class="lang-none prettyprint-override"><code>Warning: fsockopen(): SSL: crypto enabling timeout in XXX on line 2
  Warning: fsockopen(): Failed to enable crypto in XXX on line 2
  Warning: fsockopen(): unable to connect to ssl://in.mailjet.com:465 (Unknown error) in XXX on line 2
  </code></pre>
  
  <p>Output with command line</p>
  
  <pre class="lang-none prettyprint-override"><code>220 srv12.mailjet.com ESMTP Mailjet
  &lt;br/&gt;
  </code></pre>
  
  <p>Platform: I'm using PHP 5.4.11 / Apache 2.2.22 (Win32) on Windows 8 64</p>
  
  <p>-- Edit --
  I've tried using TLS as suggested:</p>
  
  <pre class="lang-php prettyprint-override"><code>$smtp = fsockopen('tls://in.mailjet.com', 567, $errno, $errstr, 30);
  </code></pre>
  
  <p>And I get</p>
  
  <pre class="lang-none prettyprint-override"><code>E_WARNING: fsockopen(): in XXX on line XXX
  </code></pre>
  
  <p>Error message is blank and <code>$errno = (int) 0</code> and <code>$errstr = (string) ''</code></p>