2017-06-21 95 views
-1

我在我的網頁上有一個電子郵件彈出窗口,其中包含三個字段:電子郵件,出生月份和出生日期。因此,如果用戶填寫這些數據並點擊提交,我希望這些數據被寫入mailchimp列表中。 有什麼辦法可以做到嗎?如何通過我的頁面發送數據到mailchimp列表

謝謝

+0

你應該考慮添加一些代碼,你如何實現的API。沒有任何信息,沒有人可以幫助你。 –

回答

1

試試這個:

function syncMailchimp($data) { 
    $apiKey = 'your api key'; 
    $listId = 'your list id'; 

    $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'], // You can add your fields here 
      'LNAME'  => $data['lastname'], 
      'DOB'  => 'mm/dd', // Add your date of birth here in mm/dd format 
     ] 
    ]); 

    $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; 
} 
+0

函數syuncMail($ data)中的$ data參數是什麼? – Stefanos

+0

這是您的$ _POST陣列.. – Sehdev

+0

您可以不使用它。在這種情況下,只需使用$ _POST而不是$ data – Sehdev

相關問題