[英]how to add email address to mailchimp list using api call in php
[英]How do I add email address to MailChimp list using API
我正在嘗試使用MailChimp API 3.0使用下面的此代碼將電子郵件地址添加到現有列表中,但它始終拋出此錯誤消息。 請任何人告訴我我的代碼有什么問題嗎?
401:您的API密鑰可能無效,或者您嘗試訪問錯誤的數據中心。
碼:
$apikey = "xxxxxxxxxxxxxxxxxxxxxxxx-us9";
$list_id = "xxxxxxxxxx";
$MD5_hashed_email_address = md5(strtolower($to_email));
$auth = base64_encode("user:$apikey");
$data = array(
"apikey" => $apikey,
"email_address" => $to_email,
"status" => "subscribed",
"merge_fields" => array(
"FNAME" => $firstname,
"LNAME" => $surname
)
);
$json_data = json_encode($data);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://us9.api.mailchimp.com/3.0/lists/$list_id/members/");
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json",
'Authorization: apikey ' . $auth));
curl_setopt($ch, CURLOPT_USERAGENT, "PHP-MCAPI/2.0");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, $json_data);
$result = curl_exec($ch);
嘗試這個:
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json", 'Authorization: Basic ' . $auth));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.