fsockopen ssl connection not working

syl.fabre 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.

Any help would be greatly appreciated :-)

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

<?php
$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) ''

phpopensslfsockopen

Answers

answered 5 years ago syl.fabre #1

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.

answered 2 years ago Andrew #2

I was having a similar problem with a contact form which uses captcha, getting the error fsockopen(): unable to connect to ssl://mail.google.com:443

This is on a FreeBSD vm, with Joomla installed.

searching, I found http://php.net/manual/en/function.fsockopen.php which mentioned certificate validation.

Installed the FreeBSD port "ca_root_nss" which includes certificate validation for Root certificates from certificate authorities included in the Mozilla NSS library

comments powered by Disqus