| Package Data | |
|---|---|
| Maintainer Username: | nztim |
| Maintainer Contact: | tim@nztim.com (Tim) |
| Package Create Date: | 2015-06-24 |
| Package Last Update: | 2025-09-19 |
| Home Page: | |
| Language: | PHP |
| License: | MIT |
| Last Refreshed: | 2025-10-23 03:03:36 |
| Package Statistics | |
|---|---|
| Total Downloads: | 1,136,713 |
| Monthly Downloads: | 28,367 |
| Daily Downloads: | 1,100 |
| Total Stars: | 99 |
| Total Watchers: | 6 |
| Total Forks: | 24 |
| Total Open Issues: | 0 |
Basic abstraction with Laravel integration for Mailchimp API v3
composer require nztim/mailchimp
config/app.php: NZTim\Mailchimp\MailchimpServiceProvider::class,
'Mailchimp' => NZTim\Mailchimp\MailchimpFacade::class,
.env value for MC_KEY (your API key)php artisan vendor:publish --provider=NZTim\Mailchimp\MailchimpServiceProvider
Mailchimp facade or inject NZTim\Mailchimp\Mailchimp using the container.$mc = new NZTim\Mailchimp\Mailchimp($apikey)
// Get an array of all available lists:
Mailchimp::getLists();
// Get lists with parameters - get IDs of lists a user is subscribed to:
Mailchimp::getLists(['email' => 'user@example.com', 'fields' => 'lists.id']);
// Check to see if an email address is subscribed to a list:
Mailchimp::check($listId, $emailAddress); // Returns boolean
// Check the staus of a subscriber:
Mailchimp::status($listId, $emailAddress); // Returns 'subscribed', 'unsubscribed', 'cleaned', 'pending', 'transactional' or 'not found'
// Adds/updates an existing subscriber:
Mailchimp::subscribe($listId, $emailAddress, $merge = [], $confirm = true);
// Use $confirm = false to skip double-opt-in if you already have permission.
// This method will update an existing subscriber and will not ask an existing subscriber to re-confirm.
// Unsubscribe a member (set status to 'unsubscribed'):
Mailchimp::unsubscribe($listId, $emailAddress);
// Directly call the API:
Mailchimp::api($method, $endpoint, $data = []); // Returns an array.
For access to all the member properties available in the v3 API, use the Member class to subscribe and update list members:
$member = (new NZTim\Mailchimp\Member($email))->merge(['FNAME' => 'First name'])->email_type('text')->confirm(false);
Mailchimp::addUpdateMember($member);
As with the subscribe() method, double-opt-in is default but existing members will not be asked to re-verify so you can use the same methods for create and update without needing to check.
Requests_Exception.NZTim\Mailchimp\MailchimpException, e.g. incorrect API key, list does not exist.NZTim\Mailchimp\Exception\MailchimpBadRequestException includes a response() method that returns the response body as an array.// Laravel:
// Subscribe a user to your list, existing subscribers will not receive confirmation emails
Mailchimp::subscribe('listid', 'user@domain.com');
// Subscribe a user to your list with merge fields and double-opt-in confirmation disabled
Mailchimp::subscribe('listid', 'user@domain.com', ['FNAME' => 'First name', 'LNAME' => 'Last name'], false);
// Subscribe/update a user using the Member class
$member = (new NZTim\Mailchimp\Member($email))->interests(['abc123fed' => true])->language('th');
Mailchimp::addUpdateMember('listid', $member);
Mailchimp::subscribe() as required