I have this code:
App::import('Vendor', 'mailchimp', array('file' => 'mailchimp/Mailchimp.php'));
$key = Configure::read("MAILCHIMP_KEY");
$list_id = 'xxxxxxxx';
$email=array('email' => $email_id);
$merge_vars = array(
'FNAME' => $fname,
'LNAME' => $lname,
'groupings' =>
array(
'name' => array('TestGroupTitle'),
'groups' => array('TestGroup')
)
);
$double_optin='false';
$mailchimp = new Mailchimp($key);
$result = $mailchimp->lists->subscribe($list_id, $email, $merge_vars, 'html', $double_optin, false, true, false);
When I first added my email id when it worked correctly, but if the same email address is added again, it shows this error: xxxx@xx.com is already subscribed to the XXX Newsletter list. Click here to update your profile.
I am not repeating anything, but still this message is coming.
I also know what error I get after some debugging:
array(
'status' => 'error',
'code' => (int) 214,
'name' => 'List_AlreadySubscribed',
'error' => 'xxxx is already subscribed to list xxxx Newsletter. Click here to update your profile.'
)
I also tried this, but nothing happened.
if ($mailchimp->errorCode) {
$error['Code'] = $this->_mailChimp->errorCode;
$error['Message'] = $this->_mailChimp->errorMessage;
pr($error);
pr($error['Code']);
}
I am using PHP and Mailchimp api 2.0. Any help would be greatly appreciated. I spent my full day on this. :(
source
share