2017 © Pedro Peláez
 

library mailchimp

MailChimp API v3 wrapper for PHP

image

slicklabs/mailchimp

MailChimp API v3 wrapper for PHP

  • Tuesday, April 24, 2018
  • by slicklabs
  • Repository
  • 3 Watchers
  • 4 Stars
  • 313 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 1 Versions
  • 22 % Grown

The README.md

MailChimp

Created with the single purpose to communicate with the MailChimp API v3 as straight forward as possible with proper error handling., (*1)

  • Uses Guzzle to make HTTP requests to the MailChimp API
  • Build for the future, PSR-1, PSR-2 & PSR-7 compliant
  • Very flexible, easily extend the MailChimp class and create your own business logic
  • Able to set MailChimp API key on the fly

Usage

Because the simple nature of this library you can call the MailChimp API methods by the desired HTTP request method., (*2)

First of all you have to include the MailChimp class., (*3)

require 'vendor/autoload.php';

use SlickLabs\MailChimp\MailChimp;
use SlickLabs\MailChimp\Exception\ResponseException;

$MailChimp = new MailChimp('MAILCHIMP-API-KEY');

For retrieving the MailChimp lists, (*4)

try {
    $response = $MailChimp->get("lists");
    echo '<pre>'; print_r($response->getBody()); echo '</pre>';
} catch(ResponseException $e) {
    echo $e->getStatusCode().'<br />';
    echo $e->getTitle().'<br />';
    echo $e->getType().'<br />';
    echo $e->getDetail().'<br />';
}

Or adding a new subscriber to a list., (*5)

$args = [
    "body" => [
        "email_address" => "myemail@myemail.com",
        "status" => "pending"
    ]
];

try {
    $response = $MailChimp->post("lists/LIST-ID/members", $args);
    echo '

'; print_r($response->getBody()); echo '
'; } catch(ResponseException $e) { echo $e->getStatusCode().'<br />'; echo $e->getTitle().'<br />'; echo $e->getType().'<br />'; echo $e->getDetail().'<br />'; }

Or updating an existing subscriber of a list., (*6)

use SlickLabs\MailChimp\Subscriber;

$args = [
    "body" => [
        "status" => "subscribed"
    ]
];

$subscriberHash = Subscriber::hash("myemail@myemail.com");

try {
    $response = $MailChimp->put('lists/LIST-ID/members/'.$subscriberHash, $args);
    echo '

'; print_r($response->getBody()); echo '
'; } catch(ResponseException $e) { echo $e->getStatusCode().'<br />'; echo $e->getTitle().'<br />'; echo $e->getType().'<br />'; echo $e->getDetail().'<br />'; }

Or deleting a subscriber of a list., (*7)

use SlickLabs\MailChimp\Subscriber;

$subscriberHash = Subscriber::hash("myemail@email.com");
try {
    $response = $MailChimp->delete("lists/LIST-ID/members/".$subscriberHash);
    echo '

'; print_r($response->getBody()); echo '
'; } catch(ResponseException $e) { echo $e->getStatusCode().'<br />'; echo $e->getTitle().'<br />'; echo $e->getType().'<br />'; echo $e->getDetail().'<br />'; }

Installation

Add MailChimp to your composer.json file. If you are not using Composer, you should be. It's an excellent way to manage dependencies in your PHP application., (*8)

{  
  "require": {
    "slicklabs/mailchimp": "dev-master"
  }
}

Then at the top of your PHP script require the autoloader:, (*9)

require 'vendor/autoload.php';

Contributing

This is a fairly simple wrapper, but it can be made much better by contributions from those using it. If you'd like to suggest an improvement, please raise an issue to discuss it before making your pull request., (*10)

Pull requests for bugs are more than welcome - please explain the bug you're trying to fix in the message., (*11)

The Versions

24/04 2018

dev-master

9999999-dev https://slicklabs.nl/

MailChimp API v3 wrapper for PHP

  Sources   Download

MIT

The Requires

 

by Leo Flapper

psr-7 mailchimp abstract