I have tried and tried to send data to MailChimp using curl but cannot get the data to save in MailChimp. Any help with this would be greatly appreciated!
Here is my code:
$mailChimpUrl = "http://us2.api.mailchimp.com/1.3/?method=listSubscribe";
$merges = array(
'FNAME'=>'Dave',
'LNAME'=>'Gilmour',
'BUILDING'=>'Central High School',
'MMERGE17' => '35904',
'MMERGE12'=>'Yes'
);
$apikey="myrealapiishere-us2";
$listId="myrealformidishere";
$email="[email protected]";
$double_optin=true;
$update_existing=false;
$replace_interests=true;
$send_welcome=false;
$email_type = 'html';
$data = array(
'email_address'=>$email,
'apikey'=>$apikey,
'merge_vars' => $merges,
'id' => $listId,
'double_optin' => $double_optin,
'update_existing' => $update_existing,
'replace_interests' => $replace_interests,
'send_welcome' => $send_welcome,
'email_type' => $email_type
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $mailChimpUrl);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
$result = curl_exec($ch);
curl_close($ch);