*_jemarea_*

Website Development

  • Home
  • Articles
    • All articles
    • Linux
    • WordPress
    • Codeigniter
    • PHP
    • JavaScript
    • MySql
  • About
  • Contact

June 2, 2018 By jerome Leave a Comment

Adding Mandrill to Codeigniter Emails

This should be quite a simple task if you are using the email library available in the default codeIgniter package.
In this case, you should have the following in your ‘application/config/autoload.php’:

$autoload['libraries'] = array(...,'email');

The 3 dots are there to show that you might have other libraries added here too. For me there is also ‘database’, ‘session’, and ‘form_validation’.

Now to the next steps:

  • Sign up to Mandrill App https://mandrillapp.com/
    You probably have to first login into Mailchimp (https://mailchimp.com/) and then open in the same browser the mandrillapp and click button “Log in through MailChimp”
  • You will have to first set up your domain on Mandrill if this is not done yet and wait until it is confirm (this might take a day or two)
  • Click then inside your Mandrill app dashoard on “Get SMTP credentials”. Copy and go to your codeigniter files..
  • Open in CodeIgniter “application/config/email.php” and this new information you got from Mandrill like this, so that you end up with something like this:
    /*
    | -------------------------------------------------------------------------
    | Email
    | -------------------------------------------------------------------------
    | This file lets you define parameters for sending emails.
    | Please see the user guide for info:
    |
    |	https://codeigniter.com/user_guide/libraries/email.html
    |
    */
    $config['mailtype'] = 'html';
    $config['charset'] = 'utf-8';
    $config['wordwrap'] = TRUE;
    $config['newline'] = "\r\n";
    
    
    //* MANDRILL
    $config['protocol'] = 'smtp';
    $config['smtp_host'] = 'smtp.mandrillapp.com';
    $config['smtp_user'] = 'information from mandrill';
    $config['smtp_pass'] = 'information from mandrill';
    $config['smtp_port'] = '587';

You are now all set.

To send emails you will probably have a function like this in one of your controllers (or maybe in a helper function):

public function sendEmail()
{
    $this->load->library('email'); // if not set in autoload.php

    $this->email->from('your@email.com', 'Your Name');
    $this->email->to('destination@email.com');
    $this->email->subject('your subject');
    $this->email->message('your message ');

    $this->email->send();
}

 

I hope this was helpful

Filed Under: Codeigniter, PHP

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Copyright © 2023 · jemarea.com