Skip to content

Instantly share code, notes, and snippets.

@gfargo
Last active August 29, 2015 14:04
Show Gist options
  • Select an option

  • Save gfargo/1b80bef682d56c8d1c4d to your computer and use it in GitHub Desktop.

Select an option

Save gfargo/1b80bef682d56c8d1c4d to your computer and use it in GitHub Desktop.
MailChimp API Integrations
<?php
/************************************************
Mail Chimp Integration with Wordpress Contact Form 7
************************************************/
function wpcf7_send_to_mailchimp($cfdata) {
//Get Data from Contact Form 7
$formtitle = $cfdata->title;
$formdata = $cfdata->posted_data;
$name = explode(" ", $formdata['your-name']);
$send_this_email = $formdata['your-email'];
// name vars for MailChimp
$mergeVars = array(
'FNAME'=>$name[0],
'LNAME'=>$name[1]
);
// grab an API Key from http://admin.mailchimp.com/account/api/
$api = new MCAPI('xxxxxxxxxxxxxxxxxxxxxxxxxxxx-xxx');
// grab your List's Unique Id by going to http://admin.mailchimp.com/lists/
// Click the "settings" link for the list - the Unique Id is at the bottom of that page.
$list_id = "xxxxxxxxx";
// Send the form content to MailChimp List without double opt-in
$retval = $api->listSubscribe($list_id, $send_this_email, $mergeVars, 'html', false);
}
// Add Hook to CF7 Mail Sent
add_action('wpcf7_mail_sent', 'wpcf7_send_to_mailchimp', 1);
?>
<!----- HTML Form Code ------!>
<div class="input-group">
[text* your-name class:form-control placeholder "John Doe"]
<span class="input-group-addon"><i class="fa fa-user"></i></span>
</div>
<div class="input-group">
[email* your-email class:form-control placeholder "[email protected]"]
<span class="input-group-addon"><i class="fa fa-envelope"></i></span>
</div>
<div class="input-group pagination-centered">
[submit class:btn class:btn-info "Sign Up"]
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment