0

I have searched this problem a lot for the past many hours and still stuck with the issue. None of the solutions have worked for me. The feature I have coded is to send mail on user registration. It was working fine till yesterday and today I am seeing a lot of issues. The problem is sometimes the mail is delivered while sometimes it randomly throws up an error.

I get the following error when I try to send an email -

Severity: Warning

Message: fsockopen(): SSL: Handshake timed out

Filename: libraries/Email.php

Line Number: 2055

Backtrace:

A PHP Error was encountered

Severity: Warning

Message: fsockopen(): Failed to enable crypto

Filename: libraries/Email.php

Line Number: 2055

Severity: Warning

Message: fsockopen(): unable to connect to ssl://smtp.gmail.com:465 (Unknown error)

Filename: libraries/Email.php

Line Number: 2055

The really annoying thing is that it comes erratically. Works sometimes and them just stops.

Following is the piece of code I use to send email - (This was working fine till yesterday)

$config = Array(
        'protocol'  => 'smtp',
        'smtp_host' => 'smtp.gmail.com',
        'smtp_port' => 465,
        'smtp_user' => 'xxxx@gmail.com',
        'smtp_pass' => 'xxxx',
        'mailtype'  => 'html',
        'charset'   => 'utf-8',
        'smtp_crypto' => "ssl"
        );

    $data = array(
   'userName'=> $firstName,
   'link'=>$url
     );

    $this->load->library('email', $config);
    $this->email->set_newline("\r\n");
    $this->email->set_mailtype("html");
    $this->email->from('finstlerforum@gmail.com', 'Finstler Support');
    $this->email->to($email);
    $this->email->subject('Please verify your email address');

    $body = $this->load->view('email-template/verifyemail',$data,TRUE);
    $this->email->message($body);
    if (!$this->email->send())
    {
        // show_error($this->email->print_debugger());
        return false;
    }
    else
    {
        return true;
    }
BenRoob
  • 1,626
  • 5
  • 22
  • 23
Ganesh T
  • 81
  • 5
  • where do you host that ? sounds like a connection or port problem – sintakonte Dec 04 '17 at 12:45
  • I have this on a wamp server on AWS ec2. Same problem on my localhost and also my colleague has same problem on his localhost. – Ganesh T Dec 04 '17 at 13:05
  • i don't know - i mean i found some similiar problem take a look @ https://stackoverflow.com/questions/34570064/gmail-fsockopen-ssl-operation-failed-error-with-codeigniter-and-xampp – sintakonte Dec 04 '17 at 13:08
  • Thank you for the help ! I had checked that link earlier. How do i check if port 465 is available or not ? I am not using any anti virus as stated in the link ! – Ganesh T Dec 04 '17 at 13:11
  • Well Ganesh ji, port 465 as to an outgoing port will be blocked only in case if the firewall is configured not to communicate over it. Else it will not be blocked. As for one possibility what i see is - **smtp.gmail.com** the domain resolution might be an issue. But that might be a remote possibility that your DNS would fail to resolve it. Other possible issue might be from google's end which might be blocking connection over some threshold limits for connection from IP address. – Blakdronzer Dec 05 '17 at 01:13
  • Thanks Blakdronzer. Well, if the port was blocked it should not work in some cases and not in other. Also, I changed the gmail account just to make sure that it is not an account level problem. But still no luck. Don't know what to do :( – Ganesh T Dec 05 '17 at 04:07
  • @GaneshT , have you found any solution? I am having the same problem. – whoosis Jan 08 '18 at 22:31
  • 1
    Comment the below code in email.php in libraries $this->_smtp_connect = fsockopen($ssl.$this->smtp_host, $this->smtp_port, $errno, $errstr, $this->smtp_timeout); and put this over there - $context = stream_context_set_default([ 'ssl' => array( 'verify_peer' => false, 'verify_peer_name' => false, 'allow_self_signed' => true ) ]); $this->_smtp_connect = stream_socket_client($ssl.$this->smtp_host.':'. $this->smtp_port, $errno, $errstr, $this->smtp_timeout, STREAM_CLIENT_CONNECT, $context); – Ganesh T Jan 09 '18 at 07:52

0 Answers0