christianezeani/mailchimp

MailChimp API wrapper

1.2.3 2019-08-03 02:51 UTC

This package is auto-updated.

Last update: 2024-04-20 11:47:16 UTC


README

Latest Stable Version Build Status Total Downloads Latest Unstable Version License

Mailchimp PHP wrapper provides a model based implementation for MailChimp API.

Installation

Package available on Packagist, and can be installed via Composer

If you're using Composer to manage dependencies, you can use

composer require christianezeani/mailchimp

Using on Laravel

For Laravel 5.5 and later, a service is automatically registered. For lower versions, manually register the service provider in config/app.php as shown below:

<?php

return [
  ...
  
  "providers" => [
    ...
    MailChimp\Framework\Laravel\MailChimpServiceProvider::class
  ]

  ...
];

Add your MailChimp API key environment variable to the projects's .env file (for development only):

MAILCHIMP_API_KEY=[Your API Key]

You can then inject MailChimp into your services and controllers.

Note that the vendor folder and the vendor/autoload.php script are generated by Composer; they are not part of MailChimp PHP Wrapper.

Alternatively, if you're not using Composer, load /path/to/mailchimp/autoload.php file manually:

<?php
require_once '/path/to/mailchimp/autoload.php';

A Simple Example

<?php
use MailChimp\Config;
use MailChimp\MailChimp;
use MailChimp\Models\Lists\Audience;

$config = new Config('_your_api_key_');
$mailChimp = new MailChimp($config);

$audience = $mailChimp->audience();

$audience->create([
  'name' => 'MailChimp Test',
  'contact' => [
    'company' => 'Demo Company Inc.',
    'address1' => 'Just a demo address',
    'city' => 'Nnewi South',
    'state' => 'Anambra',
    'zip' => '23401',
    'country' => 'Nigeria',
    'phone' => '+2347000000000'
  ],
  'permission_reminder' => 'Demo permission reminder',
  'campaign_defaults' => [
    'from_name' => 'Christian Ezeani',
    'from_email' => 'christian@example.com',
    'subject' => 'Demo Subject',
    'language' => 'en'
  ],
  'email_type_option' => false,
  'visibility' => 'prv'
]);

You'll find plenty more to play with in the examples page.

Documentation

Visit the Project site. If you're having trouble, this should be the first place you look as it's the most frequently updated.

Examples of how to use MailChimp PHP Wrapper for common scenarios can be found in the examples page.

A Complete generated API documentation is available online.

You can generate complete API-level documentation by running composer docs in the top-level folder, and documentation will appear in the docs/api folder, though you'll need to have PHPDocumentor installed. You may find the unit tests a good source of how to do various operations such as creating audience, subscribing and unsubscribing members, and many more.