php - Why isn't the Codeigniter email class sending mail with sendmail?


I'm attempting to send an email address out to registrants who register for my site however this section of my code is not running. I'm attempting to find out why. I've followed all the necessary documentation. I replaced this section with php's mail function for debugging to see if it'll send an email on my server and it will. Does anybody have any thoughts on what it could be?

// User was successfully created and the user needs to verify their account.
// Send registered an email informing them how to validate their account.
$this->email->from('[email protected]', 'Owner Name');
$this->email->subject('Site Name Here Registration');
$this->email->message('Thank you for registering for our site. Here is your registration key to activate your account: '.$registration_key.' Please click on the following link to activate your account.<br />'.anchor('project-manager/login/verify/'.$registration_key, 'Click Here To Activate Your Account', ''));


Here is the configurations for the inside of the application/config directory.

$config['protocol'] = 'sendmail';
$config['mailpath'] = '/usr/sbin/sendmail';
$config['charset'] = 'iso-8859-1';
$config['wordwrap'] = TRUE;



I know that it seems unnecessary, but I typically always use SMTP with the mail class. There are just too many server configuration issues that can result in mail not being sent. Sometimes anonymous (e.g. 'nobody' or 'www-data') users are restricted from using sendmail - a very common problem if the server isn't properly configured with suexec.

Additionally, using SMTP relies on known-good DNS / SPF settings of a known-working mail server - might not be the case on individual app servers that you use.

You could probably get to the bottom of the issue with a bit more digging, and possibly even get it corrected - but then you've got the same issue all over again if you need to move your app, or bring up more servers.

Just follow the email class documentation to use SMTP, which is just really a matter of changing the$config['protocol'] accordingly, then add the SMTP host / user / pass variables. Set up an email account, and give it a go. Mail forwarding settings can handle things likenoreply a bit more gracefully as well.

To try it, just override the$config array in your controller, e.g.:

$myTempConfig['protocol']  = 'smtp'; 
$myTempConfig['smtp_host'] = '';
$myTempConfig['smtp_user'] = 'username';
$myTempConfig['smtp_pass'] = 'swordfish';
$myTempConfig['smtp_port'] = 25;
$myTempConfig['smtp_timeout'] = 30; // adjust as needed for busy mail servers

then call:


so it loads the settings. You could just call it$config if you want, I just like making it clear what I'm doing when I do that.

It's really just better to rid yourself of the problem and be done with it once and for all. Once you have SMTP setup, your code just works, no matter where you put it.

Most decent hosting utilizes suexec correctly which means the mail class will 'just work' using sendmail. However, if you tend to deploy a lot of stuff with platform-as-a-service providers, or your own servers, it just makes better sense to use SMTP and save some headache and work.

People are also looking for solutions to the problem: How do I add a link into an xml tag using php


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.