I was not aware that you loved mailChimp. Just moved a client from constant contact for it. I would say I love it to. Here’s the code I’ve been working on. It submits the eform to create a new user. If the user is already in the list, it shows an error with an update checkbox so they can update their info if they want.
<?php
function mailchimp_signup(&$fields, &$vMsg, &$rMsg){
$update_button = '<br/><br/>';
$update_button .= 'Would you like to update your information?<br/>';
$update_button .= '<input class="checkbox" type="checkbox" name="Update_your_Information[]" value="checked" style="float:left;margin-top:3px;margin-right: 5px;" /> Check the box and click "Update"';
$update_button .= '<input class="button_norm" type="submit" value="Update" />';
$update_success = '<style type="text/css">
.wlpeMessage {background: #E6EFC2; color: #529214; border-color: #C6D880;}
.wlpeMessage .error {background: #E6EFC2; color: #529214;}
.error_heading {display: none;}
</style>';
if(!$fields['email']){
$vMsg[] = '<div class="error">No email address provided</div>';
return $vMsg;
}
if(!preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*$/i", $_POST['email'])) {
$vMsg[] = '<div class="error">Your email must contain "@" sign and have a "dot something" at the end.</div>';
return $vMsg;
}
require_once($snipPath.'MCAPI.class.php');
$api = new MCAPI('USERNAME','PASSWORD');
// Fetch mailing list id
$lists = $api->lists();
$list_id = $lists[0]['id'];
// Note: if you have more than one list you'll need to change the $lists[0] array
// (ex: second list would be 1 becaue array start counting from 0)
// Merge variables are the names of all of the fields your mailing list accepts
// Ex: first name is by default FNAME
// You can define the names of each merge variable in Lists > click the desired list > list settings > Merge tags for personalization
// Pass merge values to the API in an array as follows
$mergeVars = array(
'TITLE' => $fields['title'],
'FNAME' => $fields['First_Name'],
'LNAME' => $fields['Last_Name'],
'ADDRESS_1' => $fields['mailing_address'],
'ADDRESS_2' => $fields['mailing_address2'],
'CITY' => $fields['city'],
'STATE' => $fields['state'],
'ZIPCODE' => $fields['zip'],
'PHONE' => $fields['phone'],
'MOBILE_PHO'=> $fields['cell_phone'],
'FAX' => $fields['fax']
);
if($api->listSubscribe($list_id, $fields['email'], $mergeVars) === true) {
// It worked!
//There's no reason to have this here really.
$success = '<div class="success">Success! Check your email to confirm sign up.</div>';
}else{
// An error ocurred, return error message
if (isset($fields['Update_your_Information']))
{
//if they check update profile
if($api->listUpdateMember($list_id, $fields['email'], $mergeVars) === true)
{
echo $update_success; //reset colors for error form. i didnt want them to see the welcome to signup page. They've already signed up!
$vMsg = '';
$vMsg[] = 'Your profile has been updated';
return $vMsg;
//There is an error with the update. show update button because (1) they are already on the list, and (2) they just tried to signup again
} else {
$vMsg[] = $api->errorMessage . $update_button;
return $vMsg;
}
// There is an error with the submission. Maybe they are already on the list. If so, we show them the update checkbox
} else {
$vMsg[] = $api->errorMessage . $update_button;
return $vMsg;
}
}
}
?>
If I use it again, I’d probably make it use chunkie (for either chunk or file for the templating) and add some parameters if needed. It’s a quick start.