Welcome Guest, Not a member yet? Register   Sign In
fsockopen error with php 7.0
#1

(This post was last modified: 02-21-2016, 05:12 PM by alfred.laggner.)

I run codeigniter3.03 on digital ocean nginx and  php 7. When I try to send an email I get this error:

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

My email setup is

Code:
$config['useragent'] = 'CodeIgniter';
$config['protocol'] = 'smtp';
//$config['mailpath'] = '/usr/sbin/sendmail';
$config['smtp_host'] = 'ssl://smtp.googlemail.com';
$config['smtp_user'] = '[email protected]';
$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
Code:
extension=php_openssl.dll
enabled.

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.
Reply
#2

all you need to do is
1. enable your email
2. set your $config['smtp_timeout'] = 20; //set as long as you need
Reply
#3

Thank you freddie, I am not sure what you mean with enable email? Can you please give me more specific advice?
Reply
#4

(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.
Reply
#5

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:
Code:
//PHP 5.3 Only
        /*
        $this->_smtp_connect = fsockopen($ssl.$this->smtp_host,
                            $this->smtp_port,
                            $errno,
                            $errstr,
                            $this->smtp_timeout);
        */

Add this lines below disabled codes:

Code:
//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.
Reply
#6

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'     'smtp.gmail.com';
$config['smtp_user'     '[email protected]';
$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
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#7

(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

Thank You. Solved the issue...
Reply




Theme © iAndrew 2016 - Forum software by © MyBB