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.
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
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
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
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.
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();
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...
Do you have an email.php file in your config folder? Maybe there's a problem with your configuration in there.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With