CodeIgniter Forums

Full Version: fsockopen error with php 7.0
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I run codeigniter3.03 on digital ocean nginx and  php 7. When I try to send an email I get this error:

Severity: Warning
Message: fsockopen(): unable to connect to ssl:// (Connection timed out)
Filename: libraries/Email.php
Line Number: 1986

My email setup is

$config['useragent'] = 'CodeIgniter';
$config['protocol'] = 'smtp';
//$config['mailpath'] = '/usr/sbin/sendmail';
$config['smtp_host'] = 'ssl://';
$config['smtp_user'] = '';
$config['smtp_pass'] = 'xxxxxxxxxxxx';
$config['smtp_port'] = 465;
$config['smtp_timeout'] = 5;
$config['wordwrap'] = TRUE;
$config['wrapchars'] = 76;
$config['mailtype'] = 'html';
$config['charset'] = 'utf-8';
$config['validate'] = FALSE;
$config['priority'] = 3;
$config['crlf'] = "\r\n";
$config['newline'] = "\r\n";
$config['bcc_batch_mode'] = FALSE;
$config['bcc_batch_size'] = 200;

This version runs flawlessly in the same config under php 5.x.

in php.ini i have

I could not get any hint anywhere why this should not work in php7. Can anybody give me a hint what to check or what the cause of this error could be.
all you need to do is
1. enable your email
2. set your $config['smtp_timeout'] = 20; //set as long as you need
Thank you freddie, I am not sure what you mean with enable email? Can you please give me more specific advice?
(02-21-2016, 07:20 PM)freddy Wrote: [ -> ]all you need to do is
1. enable your email
2. set your $config['smtp_timeout'] = 20; //set as long as you need

I am not sure with what you mean with 'enable your email'. May I ask you to explain what to do to enable my email. I appreciate your support.
I have updated my servers that have PHP 5.x to 5.6 and 7, then i got same error like above.

Try this:

Disable this code:
//PHP 5.3 Only
        $this->_smtp_connect = fsockopen($ssl.$this->smtp_host,

Add this lines below disabled codes:

//PHP 5.6 & 7.0 Only Configuration
$context = stream_context_create(['ssl' => [
  //'ciphers' => 'RC4-MD5',
  'verify_host' => FALSE,
  'verify_peer_name' => FALSE,
  'verify_peer' => FALSE

$this->_smtp_connect = stream_socket_client($ssl.$this->smtp_host.':'.$this->smtp_port, $errno, $errstr, 30, STREAM_CLIENT_CONNECT, $context);
//END OF PHP 5.6 & 7.0 Only Configuration

Hope this solves that problem. Thank you.
You can try this, but also make sure that your sockets are enabled.

PHP Code:
$config['useragent'     'CodeIgniter';
$config['protocol'      'smtp';
$config['smtp_crypto'   'tls'// tls or ssl
$config['smtp_host'     '';
$config['smtp_user'     '';
$config['smtp_pass'     'xxxxxxxxxxxx';
$config['smtp_port'     587;
$config['smtp_timeout'  20;
$config['wordwrap'      TRUE;
$config['wrapchars'     76;
$config['mailtype'      'html';
$config['charset'       'utf-8';
$config['validate'      FALSE;
$config['priority'      3;
$config['crlf'          "\r\n";
$config['newline'       "\r\n";
$config['bcc_batch_mode'] = FALSE;
$config['bcc_batch_size'] = 200