Codeigniter Mailchimp Integration

Getting Started

  1. Install Codeigniter
  2. Download the Mailchimp PHP API Wrapper. I’m using version 1.3.
  3. Get a Mailchimp account
  4. Create a Mailchimp API Key
  5. Create a list in Mailchimp, and get the List ID.

Create a config file for Mailchimp
Create a new file called “mcapi.php” in Codeigniter’s /application/config/ folder.

Add the following code:

if ( ! defined('BASEPATH')) exit('No direct script access allowed');
$config['mcapi_apikey'] = 'mailchimp_api_key_here';
$config['mcapi_secure'] = true;
$config['mcapi_list_customers'] = 'mailchimp_list_id_here';

Create the library file
Rename the file MCAPI.class.php from the Mailchimp PHP API Wrapper to Mcapi.php and save it in Codeigniter’s /application/libraries/ folder.

Add the following code to the top of the file:

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

Rename the class to Mcapi. IE:

class Mcapi { ...

Change the constructor to:

public function Mcapi() { 	// Get CI Instance 	$this--->CI = &get_instance();
$this->CI->load->config('mcapi');
$this->secure = $this->CI->config->item('mcapi_secure');
$this->apiUrl = parse_url("http://api.mailchimp.com/" . $this->version . "/?output=php");
$this->api_key = $this->CI->config->item('mcapi_apikey');
unset($this->CI);
}

Basic Usage
From now on, you can load this library by simply doing this;

$this->load->library('mcapi');
$return = $this->mcapi->any_method_here();

5 Replies to “Codeigniter Mailchimp Integration”

  1. Ugghh… I’m missing something.
    “change constructor to:”
    Where in the world is the constructor in the file?
    I downloaded the 1.3, changed the MCAPI to Mcapi as instructed.
    But what am I replacing for the constructor?
    Help… please…

Comments are closed.