2017 © Pedro Peláez
 

library mailchimp-export

A library to export Mailchimp lists

image

asimlqt/mailchimp-export

A library to export Mailchimp lists

  • Saturday, January 27, 2018
  • by Asim
  • Repository
  • 1 Watchers
  • 0 Stars
  • 0 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

mailchimp-export

A simple library to export Mailchimp lists, (*1)

Requires PHP >= 7, (*2)

Installation

Use the following composer command to install, (*3)

composer require asimlqt/mailchimp-export

Example

The following is an example that exports a mailchimp list and saves it to a csv file., (*4)

<?php

require_once './vendor/autoload.php';

use Asimlqt\MailchimpExport\MailchimpException;
use Asimlqt\MailchimpExport\ListExport;
use Asimlqt\MailchimpExport\Writer\CsvWriter;

$writer = new CsvWriter(new SplFileObject("/my/path/list.csv", "w"));

try {
    $exp = new ListExport($apiKey, $listId, $writer);
    $exp->run();
} catch (MailchimpException $e) {
    echo $e->getMessage();    
}

Writers

There are currently 2 writers that are provided by default:, (*5)

CSV Writer

See example above., (*6)

Database Writer

CAUTION: The table specified will be truncated before being written to!, (*7)

This requires a little more configuration than the csv writer., (*8)

The constructor has the following definition:, (*9)

public function __construct(PDO $pdo, string $table, array $mapping)

$pdo is just a standard php pdo connection object., (*10)

$table is the name of the table that you want to write to, (*11)

$mapping is an array that maps mailchimp fields to database columns. The key of the array is the name of the mailchimp field and the value is the database column., (*12)

Example of using the database writer:, (*13)

<?php

require_once './vendor/autoload.php';

use Asimlqt\MailchimpExport\MailchimpException;
use Asimlqt\MailchimpExport\ListExport;
use Asimlqt\MailchimpExport\Writer\DatabaseWriter;

$mapping = [
    'Email Address' => 'email',
    'First Name' => 'firstname',
    'Last Name' => 'lastname',
];

$pdo = new PDO('mysql:dbname=mailchimp;host=127.0.0.1', 'user', 'password');
$writer = new DatabaseWriter($pdo, 'subscribers', $mapping);

try {
    $exp = new ListExport($apiKey, $listId, $writer);
    $exp->run();
} catch (MailchimpException $e) {
    echo $e->getMessage();
}

In the above example 'Email Address', 'First Name' and 'Last Name' are names of mailchimp fields and 'email', 'firstname' and 'lastname' are database columns they will be written to. The CsvWriter just writes everything to a csv file as is hence it doesn't require a mapping., (*14)

The data is inserted into the database in batches. The default size is 100 rows. You can set that to a different value if you wish using setBatchSize() method of DatabaseWriter, (*15)

Custom Writer

If you need to write the data elsewhere then simply extend the Writer interface which only has one method and pass it to the ListExport constructor., (*16)

interface Writer
{
    public function write(array $data);
}

The Versions

27/01 2018

dev-master

9999999-dev https://github.com/asimlqt/mailchimp-export

A library to export Mailchimp lists

  Sources   Download

Apache-2.0

The Requires

 

by Asim Liaquat

php mailchimp batch

26/01 2018

1.0

1.0.0.0 https://github.com/asimlqt/mailchimp-export

A library to export Mailchimp lists

  Sources   Download

Apache-2.0

The Requires

 

by Asim Liaquat

php mailchimp batch