fsockopen ssl connection not working

syl.fabre picture syl.fabre · Mar 25, 2013 · Viewed 11.8k times · Source

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.

php.ini

extension=php_openssl.dll line is not commented

phpinfo through Apache

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

phpinfo with command line

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

My script

$smtp = fsockopen('ssl://in.mailjet.com', 465, $errno, $errstr, 30);
$response = fgets($smtp, 4096);
if(empty($smtp)){
   echo $response;
   return false;
}
echo $response . '<br/>';
fclose($smtp);

Output under apache

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

Output with command line

220 srv12.mailjet.com ESMTP Mailjet
<br/>

Platform: I'm using PHP 5.4.11 / Apache 2.2.22 (Win32) on Windows 8 64

-- Edit -- I've tried using TLS as suggested:

$smtp = fsockopen('tls://in.mailjet.com', 567, $errno, $errstr, 30);

And I get

E_WARNING: fsockopen(): in XXX on line XXX

Error message is blank and $errno = (int) 0 and $errstr = (string) ''

Answer

syl.fabre picture syl.fabre · Apr 17, 2013

I updated my Apache version from 2.2 to 2.4 and it works now.

I've followed this tutoriel : http://lifeofageekadmin.com/how-install-apache-2-4-php-5-4-and-mysql-5-5-21-on-windows-7/ to get the new Apache version.