Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MailChimp API 2.0 Batch Subscription PHP

Tags:

php

mailchimp

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]
            )

    )
like image 699
user3555483 Avatar asked Nov 30 '22 01:11

user3555483


1 Answers

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]'));
like image 137
Ben Fortune Avatar answered Dec 30 '22 21:12

Ben Fortune