As I mentioned in my comment, you should consider the latest API 2.0. Also, this is the code that I use in a production environment.
Although it is dirty, it is functional. Just replace the merge_vars and variables with what you have. All $lead variables are pulled elsewhere in the script ... Not related to this. You should still get this idea.;)
If something else is not saved, then you have a typo. Check ALL. Took me an hour to understand that I have errors 'merge_vars' .
$merge_vars=array( 'OPTIN_IP'=>$ip, // Use their IP (if avail) 'OPTIN-TIME'=>"now", // Must be something readable by strtotime... 'FNAME'=>ucwords(strtolower(trim($lead['first_name']))), 'LNAME'=>ucwords(strtolower(trim($lead['last_name']))), 'COMPANY'=>ucwords(strtolower(trim($lead['company']))), 'ORGTYPE'=>ucwords(strtolower(trim($lead['company_type']))), 'PLANNING'=>strtolower(trim(empty($lead['planning_stage'])?"Unknown":$lead['planning_stage'])), ); $send_data=array( 'email'=>array('email'=>$lead['email']), 'apikey'=>"", // Your Key 'id'=>"", // Your proper List ID 'merge_vars'=>$merge_vars, 'double_optin'=>false, 'update_existing'=>true, 'replace_interests'=>false, 'send_welcome'=>false, 'email_type'=>"html", ); $payload=json_encode($send_data); $submit_url="https://us4.api.mailchimp.com/2.0/lists/subscribe.json"; $ch=curl_init(); curl_setopt($ch,CURLOPT_URL,$submit_url); curl_setopt($ch,CURLOPT_RETURNTRANSFER,true); curl_setopt($ch,CURLOPT_POST,true); curl_setopt($ch,CURLOPT_POSTFIELDS,$payload); $result=curl_exec($ch); curl_close($ch); $mcdata=json_decode($result); if (!empty($mcdata->error)) return "Mailchimp Error: ".$mcdata->error; return ""; // <-- This was obviously from within a function. If you made it here, it was a success
source share