Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CodeIgniter unable to send email using PHP mail()

I'm trying to send an e-mail with Codeigniter like this:

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

$this->email->from("[email protected]");
$this->email->reply_to("[email protected]");
$this->email->to("[email protected]");
$this->email->subject("Test mail");
$this->email->message("Email body");
$this->email->set_alt_message("Email body txt");
$this->email->send();

and I got this on the email debugger: Unable to send email using PHP mail(). Your server might not be configured to send mail using this method.

If I do e simple PHP mail() function with the same addresses, it works but when I use CodeIgniter it gives me the error. So why would it work with simple mail() but not with CodeIgniter ? Any ideas ?

Thanks.

like image 884
Manny Calavera Avatar asked Oct 04 '10 23:10

Manny Calavera


People also ask

Why can’t I send email using PHP mail?

codeigniter - Unable to send email using PHP mail (). Your server might not be configured to send mail using this method - Stack Overflow Unable to send email using PHP mail (). Your server might not be configured to send mail using this method

How do I send an email in CodeIgniter?

CodeIgniter has a built-in email library that we can work with when sending emails. We need to have a central place where we can manage the email settings. CodeIgniter does not come with a config file for emails so we will have to create one ourselves. Create a file email.php in the directory application/config Add the following code to email.php

How to send email in PHP using SMTP?

Add the following code to email.php ‘protocol’ => ‘smtp’, specifies the protocol that you want to use when sending email. This could be Gmail smtp settings or smtp settings from your host ‘smtp_host’ => ‘smtp.example.com’,specifies the smtp host. For example, if you want to use Gmail then you would have something like smtp.gmail.com

What are the SMTP errors in 2020-06-05?

2020-06-05 18:45:10 SERVER -> CLIENT: 535 5.7.3 Authentication unsuccessful [AM0PR10CA0059.EURPRD10.PROD.OUTLOOK.COM] 2020-06-05 18:45:10 SMTP ERROR: Password command failed: 535 5.7.3 Authentication unsuccessful [AM0PR10CA0059.EURPRD10.PROD.OUTLOOK.COM] SMTP Error: Could not authenticate.


3 Answers

Had similar issue.

That's working code from the controller :

        $config = array();
        $config['useragent']           = "CodeIgniter";
        $config['mailpath']            = "/usr/bin/sendmail"; // or "/usr/sbin/sendmail"
        $config['protocol']            = "smtp";
        $config['smtp_host']           = "localhost";
        $config['smtp_port']           = "25";
        $config['mailtype'] = 'html';
        $config['charset']  = 'utf-8';
        $config['newline']  = "\r\n";
        $config['wordwrap'] = TRUE;

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

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

        $this->email->from($fromEmail, $fromName);
        $this->email->to($email);

        $this->email->subject('Тест Email');
        $this->email->message($this->load->view('email/'.$type.'-html', $data, TRUE));

        $this->email->send();
like image 148
Fedir RYKHTIK Avatar answered Oct 20 '22 22:10

Fedir RYKHTIK


Clearly, there does not seem to be a definitive 'one size fits all' answer. What worked for me was changing

$config['protocol'] = 'smtp';

TO:

$config['protocol'] = 'mail';

Hope this helps...

like image 32
mc_kaiser Avatar answered Oct 21 '22 00:10

mc_kaiser


Do you have an email.php file in your config folder? Maybe there's a problem with your configuration in there.

like image 9
mseo Avatar answered Oct 20 '22 22:10

mseo