Welcome Guest, Not a member yet? Register   Sign In
CI email (sendmail) support

I've been trying to learn over the last few wks how to send mail via any of the several schemes I've attempted from examples both in the CI docs and from several StackOverflow posts that mostly deal with previous CI versions. But I've come up against a block for several days now. I'm not asking for a tutorial but can anyone point me to a good source that clearly and fully explains how to implement the sending of email messages from a CI coded application. 

I've tried basically everything I could find so far starting with the CI User Guide examples which use sendmail as mail client. This scheme would be my preferred configuration (just because it's the one in the CI User Guide). I'm currently getting:

Quote:Exit status code: 1
Unable to open a socket to Sendmail. Please check settings.
Unable to send email using PHP Sendmail. Your server might not be configured to send mail using this method.

In the User Guide config code:
$config['protocol'] = 'sendmail';
$config['mailpath'] = '/usr/sbin/sendmail';
$config['charset'] = 'iso-8859-1';
$config['wordwrap'] = TRUE;


I'm not sure what mailpath above refers to - I suspect that would be the path in some example directory structure. I have my 'sendmail' folder in an 'assets' folder under 'applications' in the CI directory. I'm trying to do this from my Mem_mail controller. My current attempt is:

   defined('BASEPATH') OR exit('No direct script access allowed');

    class Mem_mail extends CI_Controller {
        public function index() {   
        function sendMail() {
            $config = Array(
                'protocol' => 'sendmail',
                'mailpath' => 'base_url(assets/sendmail)',
                'mailtype' => 'html',
                'charset' => 'iso-8859-1',
                'wordwrap' => TRUE
            $this->email->from('xxx'); // change it to yours
            $this->email->to('xxx');// change it to yours
            $this->email->subject('Test Mssg');
            $message = 'This is a test message!';
            if($this->email->send()) {
                echo 'Email sent.';
            else {


StackOverflow esp. is full of statements that it won't work unless you change this or that line in php.ini for example. And almost none of those suggestions agree.  Bit I'tried making changes. None worked so I undid the changes (I hope). 

Also, I'm trying to do this from 'localhost'. I've also seen SO comments with instructions to do this but also that it probably won't work. If that's the case how do I test CI email code to know it works before I start sending faulty messages in a production environment? Any help appreciated.

(This post was last modified: 05-26-2016, 01:11 PM by cartalot.)

Just get a cheap php hosting account for doing your testing.
I will quickly add - if these emails are important - and they are single emails - not 'bulk' emails,
like you are emailing a customer to confirm a transaction, or that they just signed up for an account etc...

those kinds of emails are called "transactional emails" - and there are services that specialize in just that type of emailing.
they are very cheap and the most reliable way to send. there are different services - i'm using postmark and its fantastic
they also let you send thousands of emails before charging you :-)
this is a great intro as to why even a dedicated ip won't help
bulk versus transactional explained
and search for "codeigniter postmark" on github there are libraries there

Thanks for the advice. After following those links you provided and having a chat with the folks at postmarkapp I see that my need to occasionally contact all my active subscribers is not in the 'transactional' email category. I've found some other ESP's that do opt-in type mailing which what I believe I need. I think I'll be going in that direction. It still bothers me though that sending mail from my CI app is so darned difficult. Cheers

(This post was last modified: 05-26-2016, 10:00 PM by PaulD. Edit Reason: Added PS )

It is very easy to send email in CI. The error message said your server could not find sendmail for some reason. Your path, from what you have said, is probably wrong.

PHP Code:
'mailpath' => 'base_url(assets/sendmail)'

This is definitely wrong. It is the server path that sendmail is installed into, something like '/usr/bin/sendmail', check with your host to find out where it is on your server.

I have never used an external service for transactional emails but I am going to read what Cartalot posted and take a look. I normally just link via smtp to an existing email account, and quite honestly, this is one area I thought CI made very easy to implement. I use SMTP rather than sendmail simply because most php sent emails will get junked by spam filters, whereas sending through an existing email account is far more likely to get through.

For bulk emails, I usually use something like Mailchimp (there are hundreds) and they usually provide very powerful API's you can interact with.

Hope that helps,


PS I have read those posts now and it is certainly cheap. It is also a good idea if you are getting junked issues with your own SMTP server. It is also great that they parse return emails for you and JSON them through to your app. That was very interesting. I have found parsing emails to be a nightmare. I am not sure why a daily or weekly digest to users is not considered bulk email though, if I have 10,000 users all wanting a digest sent at midnight daily, that is surely a bulk email, and requires throttling?

Paul, Thanks for the reply. I've decided to rewrite my whole app using CI rather than just some admin tasks, as this email task was one of. I suspect that when I get back to the admin tasks, these answers here will get me going in the right direction. Esp. your comment about what 'mailpath' should point to. Regards, Ray

If you have internet service provider use there SMTP I have comcast and I set my SMTP in the php.ini to comcast SMTP and it works fine.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )

Theme © iAndrew 2016 - Forum software by © MyBB