Mailchimp Integration with Mocean API

1.0.0 2019-01-02 04:20 UTC

This package is auto-updated.

Last update: 2022-05-23 05:49:46 UTC


Mailchimp integration with Mocean Api

Try for FREE now. 20 trial SMS credits will be given upon registration. Additional SMS credits can be requested and is subject to approval by MoceanAPI.


To install the library, run this command in terminal.

composer require mocean/mailchimp


default config list

'MOCEAN_API' => '',
'MOCEAN_API_SENDER_ID' => '', //for mocean-from field (leave empty to use mailchimp list name as sender id)
'MOCEAN_API_TEXT' => 'Testing Text',

'MAILCHIMP_LISTS_SEARCH_NAME' => '', //search for mailchimp list to be used (leave this empty to use all lists)
'MAILCHIMP_CAMPAIGNS_SEARCH_TITLE' => '', //search for campaign title to be used (leave this empty to use all campaigns)

'ALLOW_DUPLICATE_MEMBER' => false, //set to true if the you wish to send to the same member in different list multiple time


If you're using composer, make sure the autoloader is included in your project's bootstrap file:

require_once "vendor/autoload.php";

Setup your configuration

$config = array(
    'MOCEAN_API_KEY' => 'xxxx',
    'MCOEAN_API_SECRET' => 'xxxx',
    'MOCEAN_API_TEXT' => 'Testing Text',
    'MAILCHIMP_API_KEY' => 'xxxx-xxx',

Create a Mailchimp object

$mailchimp = new Mocean\Mailchimp\Mailchimp($config);

Broadcast message through campaign

$totalSmsSent = $mailchimp->campaigns()->lists()->members()->broadcast();
echo "Total SMS Sent: $totalSmsSent";

Broadcast message through lists

$totalSmsSent = $mailchimp->lists()->members()->broadcast();
echo "Total SMS Sent: $totalSmsSent";

Broadcast by passing in custom text parameter (default using text in config)

broadcast('custom text');

Sometime, you would not using all campaign or list, this library provide a convenient method which you can set it in config

//seperate multiple name by (,)
$config => array(
    'MAILCHIMP_LISTS_SEARCH_NAME' => 'First List,Second List',
    'MAILCHIMP_CAMPAIGNS_SEARCH_TITLE' => 'First Campaign,Second Campaign',

Use get() if you wish to get the response data from mailchimp

$campaignResponse = $mailchimp->campaigns()->get();
$listResponse = $mailchimp->lists()->get();
$memberResponse = $mailchimp->lists()->members()->get();

Dynamically set configuration (always override current config)


API Errors

In the event of any api errors occured, the object you request will return false and you can get the specific error msg from the api class

$campaigns = $mailChimp->campaigns();
if($campaigns === false){
    echo Mocean\Mailchimp\api\MailChimpApi::$errMsg;


A Mocean\Mailchimp\exceptions\CampaignNotFoundException is thrown if the account dont have any campaign or unable to search the campaign in config

A Mocean\Mailchimp\exceptions\ListNotFoundException is thrown if the account dont have any list or unable to search the list in config

A Mocean\Mailchimp\exceptions\MemberNotFoundException is thrown if the list dont have any member

A Mocean\Mailchimp\exceptions\InvalidKeyException is thrown if there's key credential error

A Mocean\Mailchimp\exceptions\ConfigKeyNotFoundException is thrown if there's error in config key name


there's an example on usage in folder example/example.php


This library is released under the MIT License