-1

I am using CodeIgniter to send Email using this code:

$config['protocol'] = "smtp";
$config['smtp_host'] = "mail.******.com";
$config['smtp_port'] = "25";
$config['smtp_user'] = "****@****.com";
$config['smtp_pass'] = "*****";
$config['charset'] = "utf-8";
$config['mailtype'] = "html";
$config['send_multipart'] = \r\n;
$config['crlf'] = "\r\n";

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

And it succeeds when I run on an online server (public hosting).

But I got the following error when I executed the code on my own server in local.

Failed to send AUTH LOGIN command. Error: 
Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method.

User-Agent: CodeIgniter

is there any error on my code or the server config?

2 Answers2

0

Load library before initialize. May this help

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

 $config['mailtype'] = 'html';
 $config['smtp_host'] = "mail.******.com";
 $config['smtp_port'] = "25";  //465,587
 $config['smtp_user'] = "****@****.com";
 $config['smtp_pass'] = "*****";
 $config['smtp_timeout']='30';
 $config['charset']='utf-8';
 $config['protocol'] = 'smtp';
 $config['wordwrap'] = TRUE;
 $config['newline']  = "\r\n";

 $this->email->initialize($config);
Virb
  • 1,639
  • 1
  • 16
  • 25
0

It is not related to your code, it is related to the configuration of your mail server! Or try changing the Port to 587!

Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method

louk
  • 97
  • 6
  • I've tried it and then I got this error: SSL operation failed with code 1. OpenSSL Error messages: error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol – Azka Adhyastha Mar 30 '18 at 02:15