MailChimp API 2.0 Error responding to existing email address

I am trying to get a response from MailChimp to return a message to the subscriber. The subscription works fine, but I do not receive a response from MailChimp. I am Noob in PHP, so I use JSON, or can this be done, as in my code with PHP?

$MailChimp = new \drewm\MailChimp('12122338484487841-us1');
$result = $MailChimp->call('lists/subscribe', array(
        'id'                => '1123334444',
        'email'             => array('email'=>$check_mail['customers_email_address']),
        'merge_vars'        => array('FNAME'=>$check_mail['customers_firstname'], 'LNAME'=>$check_mail['customers_lastname']),
        'double_optin'      => true,
        'update_existing'   => false,
        'replace_interests' => false,
        'send_welcome'      => true,
));     

// CHECK MAILCHIMP IF EMAIL EXIST
if( $result === false ) {
    return 'You have already subscribed to the List';
}
else if( isset($result->status) && $result->status == 'error' ) {
    // Error info: $result->status, $result->code, $result->name, $result->error
}
// CHECK MAILCHIMP IF EMAIL EXIST           

thanks

+4
source share
1 answer

Cool, then you can check how ..

if( $result['name'] === 'List_AlreadySubscribed' ) {
    return $result['error'];// which returns "mail@example.com is already subscribed to list SyncTest. Click here to update your profile." as a string.
}
+8
source

All Articles