How to programmatically register a user with Mailchimp API I have a contact form with a checkbox "Register to the newsletter". If this checkbox is checked, I want to register the email adress (a field in the contact form) to the Mailchimp list, which works fine with the Mailchimp block. 

I want to do this in my contact_form_submit fonction in my module, but I can't find a way... Does anyone know how to do this ?

Thanks.

EDIT: I use this code :

if ($values['newsletter'])
{
    $list = array_shift(mailchimp_get_lists());
    mailchimp_subscribe_user($list, $values['mail'], array());
}


This code put the user in the table "cache_mailchimp_user" but not in the mailchimp list subscribers, even after I run the Drupal cron manually... Any ideas ?
Drupal 7, Mailchimp module 3.4

$list_id = '12345asd'; // use mailchimp_get_lists() and look for 'id'
$email = 'some_email@gmail.com';
if ( mailchimp_subscribe (
    $list_id,
    $email,
    array (
        'EMAIL' =&gt; $email,
        'FNAME' =&gt; $first_name, // fields in your mailchimp list
        'LNAME' =&gt; $last_name,
    ),
    false,
    false
)) {
    drupal_set_message ( t('Thank you. From now you will receive our promo materials'));
} else {
    drupal_set_message ( 'Error occurred while adding your email to subscribe list', 'error' );
}


NOTE: If mailchimp will deside that your email is invalid module will only put watchdog error. To grab that error and display you can patch mailchimp.module
find function mailchimp_subscribe_process and goto approx line 412. and add drupal_set_messaga or whatewer you want.

Approach without patching module (but it's too hacky)

$list_id = '12345asd'; // use mailchimp_get_lists() and look for 'id'
$email = 'some_email@gmail.com';
if ( mailchimp_subscribe (
    $list_id,
    $email,
    array (
        'EMAIL' =&gt; $email,
        'FNAME' =&gt; $first_name,
        'LNAME' =&gt; $last_name,
    ),
    false,
    false
)) {
    drupal_set_message ( t('Thank you. From now you will receive our promo materials'));
} else {
    // Get last watchdog mailchimp error
    $query = db_select ( 'watchdog', 'w' );
    $query -&gt; fields ( 'w' );
    $query -&gt; condition ( 'w.type', 'mailchimp', '=' );
    $query -&gt; condition ( 'w.timestamp', time() - 10, '&gt;' ); // check for message in last 10 seconds
    $query -&gt; condition ( 'w.message', 'An error occurred subscribing @email to list @list. "%message"', '=' );
    $query -&gt; orderBy ( 'w.timestamp', 'DESC' );
    $query -&gt; range ( 0, 1 );
    $ans = $query -&gt; execute();
    if ( $wd = $ans -&gt; fetchAssoc() ) {
        $wd['variables'] = unserialize ( $wd['variables'] );
        $message = $wd['variables']['%message'];
        // Get only error message
        if ( preg_match ( '#Internal\sServer\sError:(.+)$#si', $message, $m )) {
            $message = $m[1];
        }
        drupal_set_message ( $message, 'error' );
    } else {
        drupal_set_message ( 'Error occurred while adding your email to subscribe list', 'error' );
    }
}