Use MailChimp API in PHP CodeIgniter Framework

Follow given below steps:

Step 1

Download Mailchimp API File from: CodeIgniter-Library-for-MailChimp-API-v1.3.

Step 2


After then, Place MCAPI.php in given path: CodeIgniter\application\libraries- file name is MCAPI.php.

Step 3

Add mcapi.php in CodeIgniter\application\config

  1. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');  
  2.   
  3. // You MailChimp API Key  
  4. // Obtained by logging into your MailChimp account and navigating to 'Account > API Keys and Info'  
  5. $config['mcapi_apikey'] = '**********'/// mailchimp apikey  
  6.   
  7. $config['mcapi_secure'] = false;  
Step 4

Add content in CodeIgniter\application\models - your usermodel.php(your file).
  1. $this->load->library('mcapi');  
  2. $listID = '*********' ; //your mailchimp list id   
  3.   
  4. $retval = $this->mcapi->listSubscribe($listID$emailAddress);  
  5.   
  6. if ($this->mcapi->errorCode) {
       
  7.    echo "Unable to subscribe email using listSubscribe()!";   
  8.    echo "\n\tCode=".$this->mcapi->errorCode;   
  9.    echo "\n\tMsg=".$this->mcapi->errorMessage."\n";   
  10. }  

  11. else {
       
  12.    echo $emailAddress." added successfully\n";   
  13. }  

 

Ebook Download
View all
Learn
View all