【发布时间】:2014-10-23 00:38:07
【问题描述】:
我已经尝试并尝试使用 curl 向 MailChimp 发送数据,但无法获取 要保存在 MailChimp 中的数据。对此的任何帮助将不胜感激!
这是我的代码:
$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="zz22@aol.com";
$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);
【问题讨论】:
-
mailchimp 返回什么?
-
首先,我建议您使用最新的 2.0 API... 类似的结构,但它们简化了一些事情。
-
第二,切勿将未加密的连接用于任何 API 集成。