PHPackages                             faimmedia/mailchimp-v3-api - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. faimmedia/mailchimp-v3-api

ActiveLibrary

faimmedia/mailchimp-v3-api
==========================

Easy to use MailChimp v3 API library for PHP

0.0.1(9y ago)01.6k[2 issues](https://github.com/FaimMedia/MailChimp-v3-API/issues)MITPHPPHP &gt;=5.6

Since Nov 30Pushed 9y ago1 watchersCompare

[ Source](https://github.com/FaimMedia/MailChimp-v3-API)[ Packagist](https://packagist.org/packages/faimmedia/mailchimp-v3-api)[ Docs](https://github.com/faimmedia/mailchimp-v3-api/)[ RSS](/packages/faimmedia-mailchimp-v3-api/feed)WikiDiscussions master Synced today

READMEChangelogDependenciesVersions (3)Used By (0)

MailChimp PHP v3 API library by FaimMedia.nl
============================================

[](#mailchimp-php-v3-api-library-by-faimmedianl)

I couldn't find a good simple PHP library for the MailChimp v3 API, so decided to created one.
Currently it has basic support for `campaigns` (including some `actions`), `lists` and corresponding `members`. No tests are included at this moment, so please create an issue for any unexpected results you might run into.

Installation
------------

[](#installation)

You can install this library by editing (or creating) your `composer.json`:

```
{
	"require": {
		"faimmedia/mailchimp-v3-api": "*"
	}
}

```

And run `composer update` or `composer install`.

Usage
-----

[](#usage)

There are some more examples in the `example` folder. All methods can be found in the section below.

All examples below require the initialization of the MailChimp class with your API key. The API key is a 32-length hash followed by your MailChimp datacenter location, separated with a minus. An API key can be obtained here: .

```
$apiKey = '02699f222d95d4dfc53b9f7960b2fa6e-us1';

$mailchimp = new FaimMedia\MailChimp($apiKey);

```

For all API end-points, required and allowed fields, please check out the MailChimp API documentation page: .

### Campaigns

[](#campaigns)

#### Create a new campaign

[](#create-a-new-campaign)

```
$campaign = $mailchimp->campaigns()->create([
	'settings' => [
		'subject_line' => 'My newsletter',
		'from_name'    => 'My company',
		'reply_to'     => 'newsletter@mycompany.com',
	],
	'type'     => 'regular',
]);

```

#### Get all existing campaigns

[](#get-all-existing-campaigns)

```
$campaigns = $mailchimp->campaigns()->getAll();

```

#### Get campaign by id

[](#get-campaign-by-id)

```
$campaign = $mailchimp->campaigns()->getById($campaignId);
// or
$campaign = $mailchimp->campaigns($campaignId);

```

### Campaign content

[](#campaign-content)

#### Set content of a campaign

[](#set-content-of-a-campaign)

```
$campaign->setContentItem([
	'html' => 'HTML content of my campaign',
	'text' => 'Text content of my campaign'
]);

```

#### Get content of a campaign

[](#get-content-of-a-campaign)

```
$content = $campaign->getContentItem();
echo $content->getHtml();
echo $content->getText();

```

### Campaign actions

[](#campaign-actions)

#### Send a campaign

[](#send-a-campaign)

```
$campaign->actions()->send();

```

#### Send test mail for campaign

[](#send-test-mail-for-campaign)

```
$campaign->actions()->test();

```

#### Schedule a campaign

[](#schedule-a-campaign)

The schedule method only excepts a `DateTime` object as first argument.

```
$datetime = new \DateTime('2018-02-01 01:00:00');

$campaign->actions()->schedule($datetime);

```

#### Unschedule a campaign

[](#unschedule-a-campaign)

```
$campaign->actions->unschedule();

```

### Lists

[](#lists)

#### Create a new list

[](#create-a-new-list)

```
$list = $mailchimp->lists()->create([
	'name'     => 'Test newsletter list',
	'contact'  => [
		'company'  => 'FaimMedia.nl',
		'address1' => 'PO Box 1540',
		'city'     => 'NIJMEGEN',
		'state'    => 'GL',
		'zip'      => '6501 BM',
		'country'  => 'NL',
	],
	'permission_reminder' => 'You signed up for updates on our website',
	'campaign_defaults'   => [
		'from_name'    => 'FaimMedia.nl',
		'from_email'   => 'john.doe@repo.github.com',
		'subject'      => 'Newsletter',
		'language'     => 'NL',
	],
	'email_type_option' => false,
]);

```

*Returns:* `ListItem` object

#### Get all existing lists

[](#get-all-existing-lists)

```
$lists = $mailchimp->lists()->getAll();

```

*Returns:* `Lists` object

#### Get list by id

[](#get-list-by-id)

```
$list = $mailchimp->lists()->getById($listId);
// or
$list = $mailchimp->campaigns($listId);

```

*Returns:* `ListItem` object

### List members

[](#list-members)

This class and methods can be used to subscribe or unsubscribe list members. When adding a member or updating the subscription status of an existing member, it's not being checked if the member exists. If it already exists the provided data will be overridden, if it doesn't exists the member will be created with the provided subscription status.

#### Add one list member (subscriber)

[](#add-one-list-member-subscriber)

Subscribe can simple add one subscriber to the list, by using the `add` method. If you wish to subscribe multiple members to a list at once, it is recommended to use the `multi` method instead of the `add` method. The `add` method will make a new request for every email address, were `multi` can send a whole batch of email addresses at once.

```
$member = $list->members()->add('johndoe@repo.github.com');

```

*Returns:* `ListMemberItem` object

If you wish to include additional fields, you can specify an array as first attribute.

```
$member = $list->members()->add([
	'email_address' => 'john.doe@repo.github.com',
	'merge_fields'  => [
		'FNAME' => 'John',
		'LNAME' => 'Doe',
	],
]);

```

*Returns:* `ListMemberItem` object

#### Subscribe multiple list members

[](#subscribe-multiple-list-members)

If you wish to add multiple members to a list, you can use the `multi` method.

```
$members = $list->members()->multi([
	'john.doe@repo.github.com',
	'jane.doe@repo.githib.com',
]);

```

This method also provides a way to included multiple fields, you can simple specify the email address as array key in that case:

```
$members = $list->members()->multi([
	'john.doe@repo.github.com' => [
		'merge_fields' => [
			'FNAME' => 'John',
			'LNAME' => 'Doe',
		],
	],
	'jane.doe@repo.github.com' => [
		'merge_fields' => [
			'FNAME' => 'Jane',
			'LNAME' => 'Doe',
		],
	],
]);

```

*Returns:* `ListMembers` object

#### Get a list member

[](#get-a-list-member)

```
$member = $list->members()->getByEmail('john.doe@repo.github.com');

```

*Returns:* `ListMemberItem` object

#### Change status of a list member

[](#change-status-of-a-list-member)

This method changes the list member status and immidiatly saves it.

```
$member->setStatus('unsubscribed');

```

*Returns:* `ListMemberItem` object

### Items

[](#items)

#### Getting properties

[](#getting-properties)

All objects returning a `AbstractItem` instance (`CampaignItem`, `ListItem`, `ListMemberItem`) can easily return the properties. All properties are accessable by calling the camelcased field prefix with get. In example, if you'd wish to get the `email_address` field, you could use the `getEmailAddress` method.

```
foreach($members as $member) {
	echo $member->getId();
	echo $member->getEmailAddress();
	echo $member->getMergeFields()->getFNAME();
	echo $member->getMergeFields()->getLNAME();

// or

	echo $member->id;
	echo $member->emailAddress;
	echo $member->mergeFields->FNAME;
	echo $member->mergeFields->LNAME;
}

```

If the value is an array, you could pass the first argument of the method to get that key of the array:

```
$member->getMergeFields('FNAME');

```

If you would like to get the property by it's `snakecase` key, you could use the `get` method.

```
$member->get('id');
$member->get('email_address');
$member->get('merge_fields')->get('FNAME');
$member->get('merge_fields')->get('LNAME');

```

To get the name of the subscriber more easily there are a few build-in methods:

```
$member->getFirstName();
// alias of $member->getMergeFields()->getFNAME();

$member->getLastName();
// alias of $member->getMergeFields()->getLNAME();

```

#### Get all properties

[](#get-all-properties)

Use the `toArray` method, to get an array of all properties.

```
$campaign->toArray();
$member->toArray();
$list->toArray();

```

#### Delete an item

[](#delete-an-item)

You can delete items by using the `delete` method. This method returns `true` on success or throws an `Exception` on failure. Campaigns that are on `sending` status can not be deleted. Also lists that are linked to a campaign can't be deleted, in that case you need to delete the campaign first.

```
$list->delete();

$campaign->delete();

```

Subscribe members can be deleted, however it's not recommended according to the MailChimp API documentation. It's better to update the current member and change it's `status` to `unsubscribed`.

```
$member->delete();

// better to unsubscribe

$member->setStatus('unsubscribed');

```

### Update items

[](#update-items)

First get the item you would like to update:

```
// campaigns
$campaign = $mailchimp->campaigns()->getById();

// lists
$list = $mailchimp->lists()->getById('ag43fe');

// members
$list->members()->getByEmail('john.doe@repo.github.com');

```

Update the fields that need changes. If you use the overloading property (`$campaign->type = 'html'`), it expects a camelized field, were the `set` method expects the regular snakecased fields.

```
// campaigns
	$campaign->type = 'plaintext';
	// or
	$campaign->set('type', 'plaintext');
	// or
	$campaign->set([
		'settings' => [
			'subject_line' => 'New subject line',
			'title'        => 'Updated campaign title',
		]
	]);

// lists
	$list->name = 'Updated list name';
	// or
	$list->set('name', 'Updated list name');
	// or
	$list->set([
		'name'       => 'Updated list name',
		'visibility' => 'prv',
	]);

// members
	$member->status = 'cleaned';
	// or
	$member->set('status', 'cleaned');
	// or
	$member->set([
		'status'       => 'cleaned',
		'merge_fields' => [
			'FNAME' => 'Test',
		],
	]);

```

*Please note* that modifing multi-dimensional properties this way will not work, in example:

```
$campaign->settings->subjectLine = 'Updated campaign title';

```

You'll need to provide an array to the first property:

```
$campaign->settings = [
	'subject_line' => 'Updated campaign subject line',
];

```

The new array will be merged with the old one, to if you ommit a certain field (in this case, in example, the `title` field) the original `title` will be kept.

If you don't want this behaviour you could pass an extra argument to the `set` method. This way the array would not be merged, but overwritten:

```
$campaign->set('settings', [
	'subject_line' => 'Updated campaign subject line',
], false);

```

Save the item:

```
$campaign->save();

$list->save();

$member->save();

```

Methods
-------

[](#methods)

Will be provided soon...
See all examples for now, they included most methods.

Exceptions
----------

[](#exceptions)

All exceptions are extended from `MailChimpException`.

### ItemException

[](#itemexception)

Throw when an item could not be found.

### SaveException

[](#saveexception)

Thrown when there was an error saving the item.

### RequestException

[](#requestexception)

Thrown when there was a problem with the MailChimp API request, could be when the request itselfs fails or when the MailChimp API returns an unexpected response.

###  Health Score

26

—

LowBetter than 46% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

3398d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/024ab16807383628de696767bd28cba0fad1517d115e9046e5333d83f7d08ead?d=identicon)[FaimMedia](/maintainers/FaimMedia)

---

Top Contributors

[![FaimMedia](https://avatars.githubusercontent.com/u/11771199?v=4)](https://github.com/FaimMedia "FaimMedia (20 commits)")

### Embed Badge

![Health badge](/badges/faimmedia-mailchimp-v3-api/health.svg)

```
[![Health](https://phpackages.com/badges/faimmedia-mailchimp-v3-api/health.svg)](https://phpackages.com/packages/faimmedia-mailchimp-v3-api)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
