Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MailChimp API 2.0 Error Response for existing E-Mail Address

Tags:

php

mailchimp

I am trying to get a response from MailChimp to return a message to the Subscriber. The subscribtion is working fine but I do not get any response from MailChimp. I am a Noob at PHP so do I neeed to use JSON or can it be done like 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

like image 852
karadayi Avatar asked Feb 15 '23 07:02

karadayi


1 Answers

Cool , then you can check like..

if( $result['name'] === 'List_AlreadySubscribed' ) {
    return $result['error'];// which returns "[email protected] is already subscribed to list SyncTest. Click here to update your profile." as a string.
}
like image 65
Shankar Narayana Damodaran Avatar answered Feb 23 '23 15:02

Shankar Narayana Damodaran