Hi everybody,
I’m trying to integrate eForm with the Mailchimp API. Basically, i want it so when someone submits the eform, it takes their first name, surname and email address, submits it to mailchimp thro the api and then carries on as normal with eform.
I have this so far:
<?php
include_once('/var/www/vhosts/domain.com/httpdocs/assets/snippets/mcapi/MCAPI.class.php');
function signUpEmail(&$fields){
if($fields['signup']){
include_once('/var/www/vhosts/domain.com/httpdocs/assets/snippets/mcapi/config.inc.php');
$api = new MCAPI($apikey);
$email = $_POST["email"];
$merge_vars = array('');
$retval = $api->listSubscribe( $listId, $email, $merge_vars, '', false, '', '', false);
if ($api->errorCode){
$m = "$listId - Unable to load listSubscribe()!\n" ."\tCode=".$api->errorCode."\n" . "\tMsg=".$api->errorMessage."\n";
$modx->logEvent(29, 1, $m . ' ON ' .$email, 'MailChimp');
} else {
//$modx->logEvent(29, 1, $retval . ' ON ' .$email, 'MailChimp');
}
}
}
?>
I include the snippet on the page with [!signUpEmail!]
then submit &eFormOnBeforeMailSent=`signUpEmail` in my eform code.
I’ve tried to adapt a post from a while back, but it doesnt add the user to mailchimp because its not getting the email address and name data from the eform. Anyone with php skills can prob fix this in a few mins as im 100% sure im overlooking a few things.
Any advice would be great.
Thanks
André