4
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'smtp.gmail.com',
'smtp_port' => 465,
'smtp_user' => 'XXXX@XXXX.com',
'smtp_pass' => 'XXXX',
'mailtype'  => 'html', 
'charset'   => 'iso-8859-1'
);
$this->load->library('email', $config);
$this->email->set_newline("\r\n");

$this->email->from('xxxxx@xxx.com', 'xxxx');
$this->email->to($email);

$this->email->subject('Hi');
$this->email->message('Hi');

if($this->email->send())
{
echo 'Your email was sent.';
}

else
{
show_error($this->email->print_debugger());
}

But it shows the error Message: fsockopen(): unable to connect to smtp.gmail.com:465 (Connection refused).

I have seen the solution here Sending mail with CodeIgniter using SMTP protocol not working but it is not working and I am not able to find php.ini.

Community
  • 1
  • 1
Shaleen Jain
  • 177
  • 1
  • 11

1 Answers1

0

I am using this way and it is working for me:

$config = array(
       'protocol'  =>  'smtps',
       'smtp_host' =>  'ssl://smtps.googlemail.com',
       'smtp_user' =>  DONOT_EMAIL,
       'smtp_pass' =>  EMAIL_PASSWORD,
       'smtp_port' =>  '465',
       'mailtype'  =>  'html',
       'smtp_timeout' => '4',
       'newline'   => "\r\n"
      );

This code i used for server side. Make sure that every time you used the mail functionality in local or server. Initialize first like this:

$this->email->initialize($config);
Chaitanya Desai
  • 333
  • 3
  • 17