我是mailchimp的新手.刚才我创建了帐户并获得了api密钥.我已经通过他们的api添加电子邮件地址列表但没有帮助它.
我联系我们表格,当用户点击提交按钮时,我想在我的mailchimp数据库中添加用户的电子邮件ID.
$apikey = '***********-us3';
$listID = '*******';
$email = "********";
$url = sprintf('https://us2.api.mailchimp.com/2.0/lists/subscribe&apikey=%s&id=%s&email_address=%s&output=json', $apikey, $listID, $email, $_SERVER['REMOTE_ADDR']);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($ch);
$arr = json_decode($data, true);
curl_close($ch);
if ($arr == 1) {
echo 'Check Now your e-mail and confirm your subsciption.';
} else {
echo $arr['code'];
switch ($arr['code']) {
case 214:
echo 'You are already subscribed.';
break;
// check the MailChimp API for more options
default:
echo 'Unkown error...';
break;
}
}
任何人都可以建议我如何实现它?
提前致谢
解决方法:
mailchimp在https://bitbucket.org/mailchimp/mailchimp-api-php提供了一个PHP包装器,这使得生活变得容易一百万次.
这里似乎发生的问题是你正在进行GET而不是POST
尝试
$apikey = '**********-us3';
$listID = '******';
$email = "**************";
$fields = array('apikey' => urlencode($apikey), 'id' => urlencode($listID), 'email_address' => urlencode($email), 'output' => 'json' );
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string, '&');
$url = 'https://us2.api.mailchimp.com/2.0/lists/subscribe';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
$data = curl_exec($ch);
$arr = json_decode($data, true);
curl_close($ch);
if ($arr == 1) {
echo 'Check Now your e-mail and confirm your subsciption.';
} else {
echo $arr['code'];
switch ($arr['code']) {
case 214:
echo 'You are already subscribed.';
break;
// check the MailChimp API for more options
default:
echo 'Unkown error...';
break;
}
}
如果有帮助,请告诉我.如果没有,我可以看看我是否可以尝试自己设置,以便我可以测试一些代码.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。