SMTP protocol for sending mail does not work with codeigniter

$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 an error message: fsockopen (): cannot connect to smtp.gmail.com-00-0065 (connection rejected).

I saw the solution here Sending mail using CodeIgniter using the SMTP protocol does not work , but it does not work, and I can not find php.ini.

+4
source share
1 answer

I use this method and it works 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"
      );

I used this code for the server. Make sure every time you use the mail features on a local or server. Initialize first like this:

$this->email->initialize($config);
0
source

Source: https://habr.com/ru/post/1669289/


All Articles