user3555483
user3555483

Reputation: 190

MailChimp API 2.0 Batch Subscription PHP

I am not able to subscribe multiple emails in MailChimp. Using API https://bitbucket.org/mailchimp/mailchimp-api-php/downloads

$api_key = "***";
$list_id = "***";

require ('api/Mailchimp.php');
$Mailchimp = new Mailchimp($api_key);
$Mailchimp_Lists = new Mailchimp_Lists($Mailchimp);


$batch[] = array('email' => '[email protected]');
$batch[] = array('email' => '[email protected]');

$subscriber = $Mailchimp_Lists -> batchSubscribe($list_id, $batch, false, false, true);

I am getting following Error:

[errors] => Array
    (
        [0] => Array
            (
                [code] => -99
                [error] => An email address must contain a single @
                [email] => [email protected]
            )
        [0] => Array
            (
                [code] => -99
                [error] => An email address must contain a single @
                [email] => [email protected]
            )

    )

Upvotes: 4

Views: 2980

Answers (1)

Ben Fortune
Ben Fortune

Reputation: 32127

Email should be a struct, not a string.

$batch[] = array('email' => '[email protected]');
$batch[] = array('email' => '[email protected]');

Should be

$batch[] = array('email' => array('email' => '[email protected]'));
$batch[] = array('email' => array('email' => '[email protected]'));

Upvotes: 20

Related Questions