0
我試圖插入數據到mailchip使用下面的代碼,但它不工作,問題與我的新領域'Q1' => "50000",
當我將刪除這然後能夠成功添加,但我需要插入額外領域。我需要插入電子郵件,姓名,Q1,Q2,Q3,Q4和Q5。Mailchimp插入自定義表單域
這裏是mailchimp形式Q1字段設置
而且我的PHP代碼:
$data = [
'email' => '[email protected]',
'status' => 'subscribed',
'firstname' => 'john',
'lastname' => 'doe'
];
Mailchimp($data);
function Mailchimp($data) {
$apiKey = 'XXXXXXXXXXXXXXXXX';
$listId = 'XXXXXXXX';
$memberId = md5(strtolower($data['email']));
$dataCenter = substr($apiKey,strpos($apiKey,'-')+1);
$url = 'https://' . $dataCenter . '.api.mailchimp.com/3.0/lists/' . $listId . '/members/' . $memberId;
$json = json_encode([
'email_address' => $data['email'],
'status' => $data['status'], // "subscribed","unsubscribed","cleaned","pending"
'merge_fields' => [
'FNAME' => $data['firstname'],
'LNAME' => $data['lastname'],
'Q1' => "50000",
],
]);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_USERPWD, 'user:' . $apiKey);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
$result = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
return $httpCode;
}
任何幫助將不勝感激
嘗試下探後'「50000」'最後一個逗號,看看列是mailchimp? – Syfer
嘗試但沒有結果相同的問題 –
當您在'merge_fields'中包含'Q1'時,您從MailChimp API收到的回覆是什麼?如果出現錯誤,則響應可能會包含一條消息,說明可能發生了什麼問題。另外,你確定'Q1'的合併域是否被創建? – Terry