Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

codeigniter

$config = array(
    'protocol' => 'smtp',
    'smtp_host' => 'ssl://smtp.gmail.com',
    'smtp_port' => '465',
    'smtp_user' => "[email protected]", 
    'smtp_pass' => "xxxxxxx", // change it to yours
    'mailtype'  => 'html', 
    'charset'   => 'utf8'
);

$this->load->library('email',$config);

$this->email->set_newline("\r\n");
$this->email->set_crlf( "\r\n" );

$this->email->from($config['smtp_user']);
$this->email->to($email['user_email']);         
$this->email->subject($row['tplsubject']);
$this->email->message(html_entity_decode($email_subject));
$this->email->send();

This code not working its showing error

A PHP Error was encountered

Severity: Warning

Message: fsockopen(): unable to connect to ssl://smtp.gmail.com:465 (Unable to find the socket transport "ssl" - did you forget to enable it when you configured PHP?)

Filename: libraries/Email.php

Line Number: 1689

like image 759
suresh kannan Avatar asked Jul 05 '16 12:07

suresh kannan


2 Answers

I am facing the same problem with Email on a server, the solution for this problem is to change the 'protocol' from 'smtp' to 'ssmtp' and 'smtp_host' from 'ssl://smtp.gmail.com' to 'ssl://ssmtp.googlemail.com'. This thing is working fine for me.

like image 89
abhishek Avatar answered Nov 12 '22 14:11

abhishek


This is not a codeigniter problem, but a php settings related problem. The answer to this question can be found here: Unable to find the socket transport "ssl" - did you forget to enable it when you configured PHP?

One thing to note is that in codeigniter you can use an e-mail config file, to hold all your config settings. (so you don't have to define them each time in a controller). You can do this by creating the file: application/config/email.php you can then fill this file with your settings, like this:

<?php defined('BASEPATH') OR exit('No direct script access allowed');

$config = array(
    'protocol' => 'smtp', // 'mail', 'sendmail', or 'smtp'
    'smtp_host' => 'your_host',
    'smtp_port' => your_port,
    'smtp_user' => 'your_email',
    'smtp_pass' => 'your_password',
    'smtp_crypto' => 'security', //can be 'ssl' or 'tls' for example
    'mailtype' => 'html', //plaintext 'text' mails or 'html'
    'smtp_timeout' => '4', //in seconds
    'charset' => 'iso-8859-1',
    'wordwrap' => TRUE
);

each time you load the library ($this->load->library('email');) these settings will be automatically loaded.

Also I recommend that you change your e-mail password immediately because you wrote your credentials in your question.

like image 26
notStan Avatar answered Nov 12 '22 13:11

notStan