Skip to content

Instantly share code, notes, and snippets.

@victor-falcon
Created March 12, 2012 10:47
Show Gist options
  • Save victor-falcon/2021125 to your computer and use it in GitHub Desktop.
Save victor-falcon/2021125 to your computer and use it in GitHub Desktop.
Saving Contact Form 7 data into a MailChimp List
<?php
/*
Guardando email de Contact Form 7 en MailChimp
Necesita el archivo MCAPI.class.php de la API de MailChimp
En este en concreto usamos un checbox con el nombre subscribe para comprobar si el
usuario quiere subscribirse o no. En caso afirmativo guardamos el nombre y el email
en la lista concreta de nuestro MailChimp.
// http://www.bigbossmas.com/wordpress/integrating-contact-form-7-to-mailchimp-the-better-way/
*/
function wpcf7_send_to_mailchimp($cfdata) {
$formtitle = $cfdata->title;
$formdata = $cfdata->posted_data;
if ( $formdata['subscribe'] ) {
$send_this_email = $formdata['your-email'];
$mergeVars = array('FNAME'=>$formdata['your-name']);
// MCAPI.class.php needs to be in theme folder
require_once('MCAPI.class.php');
// grab an API Key from http://admin.mailchimp.com/account/api/
$api = new MCAPI('----- API KEY -----');
// 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 = "----- UNIQUE ID LIST -----";
// Send the form content to MailChimp List without double opt-in
$retval = $api->listSubscribe($list_id, $send_this_email, $mergeVars, 'html', false);
}
}
add_action('wpcf7_mail_sent', 'wpcf7_send_to_mailchimp', 1);
?>
@joelwolfgang
Copy link

Should this work for multiple Contact Form 7 Forms? I have it working very well on one, but I need it to work on several and the others aren't functioning.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment