3
我正在尋找一些幫助,找出爲什麼這個基本腳本不適合我。我試圖使用MailChimp API來定製表單將新訂戶添加到列表中。腳本沒有返回任何東西。需要基本的MailChimp API幫助
我知道我正確地使用了API,因爲當我直接在瀏覽器中輸入url時,該對象在MailChimp中訂閱,這讓我覺得curl沒有設置正確。有什麼想法嗎?
<?php
$apikey = 'xxx';
$listID = 'yyy';
$email = htmlspecialchars(stripslashes(trim($_POST['EMAIL'])));
$fname = htmlspecialchars(stripslashes(trim($_POST['FNAME'])));
$lname = htmlspecialchars(stripslashes(trim($_POST['LNAME'])));
if (!empty($_POST['EMAIL_UPDATES'])) {
$url = sprintf('http://us6.api.mailchimp.com/1.3/?method=listSubscribe&apikey=%s&id=%s&email_address=%s&merge_vars[OPTINIP]=%s&merge_vars[FNAME]=%s&merge_vars[LNAME]=%s&merge_vars[ZIP]=%s&output=json', $apikey, $listID, $email, $_SERVER['REMOTE_ADDR'], $fname, $lname);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($ch);
curl_close($ch);
$arr = json_decode($data, true);
if ($arr == 1) {
echo 'Check your e-mail and confirm your subscription.';
} else {
switch ($arr['code']) {
case 214:
echo 'You are already subscribed.';
break;
// check the MailChimp API for more options
default:
echo 'Unknown error.';
break;
}
}
}
?>
在關閉句柄之前使用'curl_error($ ch)'檢查捲曲錯誤。 – Jrod