lorddashme/php-mailchimp

A PHP package wrapper for MailChimp API.

3.1.0 2018-09-27 10:52 UTC

This package is auto-updated.

Last update: 2024-03-30 00:17:05 UTC


README

A PHP package wrapper for MailChimp API.

This package support only the version 3 of Mailchimp API.

Latest Stable Version Minimum PHP Version Coverage Status

Requirement(s)

  • PHP version from 5.6.* up to latest.

Install

  • It is advice to install the package via Composer. Use the command below to install the package:
composer require lorddashme/php-mailchimp

Usage

  • Below are the available functions:
Function Description
post('route', closure/array); To request in the MailChimp API service using POST method. The body parameter accepts Cloure or Array type.
get('route'); To request in the MailChimp API service using GET method.
patch('route', closure/array); To request in the MailChimp API service using PATCH method. The body parameter accepts Cloure or Array type.
delete('route'); To request in the MailChimp API service using DELETE method.
action('route'); To request in the MailChimp API service using the custom ACTION.
getRequest(); To check the current request details. Can be use for debugging purposes.
getRespose(); To get the current response from the MailChimp API service.
Response Format:
{"response_body": {...}", "header": {"response_http_code": ...}}
  • Basic usage:
<?php

include __DIR__  . '/vendor/autoload.php';

use LordDashMe\MailChimp\MailChimp;

$apiKey = 'abcde12345...';

$mailchimp = new MailChimp($apiKey);

$listId = 'qwerty12345...';

$mailchimp->post("list/{$listId}/members", function ($requestBody) {
    $requestBody->email_address = 'sample_email@mailchimp.com';
    return $requestBody;
});

// If you want to investigate the current request details.
$mailchimp->getRequest();

// To get the response from the MailChimp API service.
// Response: {"response_body": {...}", "header": {"response_http_code": ...}}
$response = $mailchimp->getResponse();
  • Also can be done by using the below code:
<?php

include __DIR__  . '/vendor/autoload.php';

use LordDashMe\MailChimp\Facade\MailChimp;

$apiKey = 'abcde12345...';

MailChimp::init($apiKey);

$listId = 'qwerty12345...';

MailChimp::post("list/{$listId}/members", array(
    'email_address' => 'sample_email@mailchimp.com'
));

MailChimp::getRequest();

// Response: {"response_body": {...}", "header": {"response_http_code": ...}}
$response = MailChimp::getResponse();

License

This package is open-sourced software licensed under the MIT license.