Sending email using codeigniter email class

I have an error trying to send an email using codeigniter email Class.

I have an error: Failed to connect to the mail server on port "localhost" 25, check the settings "SMTP" and "smtp_port" in php.ini or use ini_set ()

How can I check email sending in codeigniter ?. I also use localhost. Does this problem only occur when using localhost?

Here is my code:

public function emailme() {
        $this->load->library('email');
        $message = $this->input->post('email_msg');
        $this->email->from('iamjohnx3303@yahoo.com', 'John');
        $this->email->to('iamjohnx3302@gmail.com');
        $this->email->subject('Email Test');
        $this->email->message($message);
        $this->email->send();
    }
+4
source share
1 answer

configuration sendmail.ini

way c:\xampp\sendmail\sendmail.ini

Configuration

[sendmail]

smtp_server=smtp.gmail.com
smtp_port=25
error_logfile=error.log
debug_logfile=debug.log
auth_username=myemail@gmail.com
auth_password=yourgmailpassword
force_sender=myemail@gmail.com

in php.ini

way c:\xampp\xampp\php\php.ini

[mail function]
sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"

then

$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => 465,
'smtp_user' => 'xxx@gmail.com',// your mail name
'smtp_pass' => '*****',
'mailtype'  => 'html', 
'charset'   => 'iso-8859-1'
 'wordwrap' => TRUE
);

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

XAMPP mail settings (important)

$this->email->from('mygmail@gmail.com', 'myname');//your mail address and name
$this->email->to('target@gmail.com'); //receiver mail

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

$this->email->send(); //sending mail
+4

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


All Articles