Create MailChimp API key
Login to your mailchimp account and navigate to Account -> Extras -> API Keys
Get unique list id
Got to lists on top menu and then click on down arrow next to the “stats” button.
PHP code to add user to list
Configure your API call
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
$api = "YOUR-API-KEY-GOES-HERE-us8"; $url = 'https://<dc>.api.mailchimp.com/2.0/'; $method = "lists/subscribe"; $return = ".json"; $datacentre = explode('-', $api); $url = str_replace('<dc>', $datacentre[1], $url); $final_url = $url.$method.$return; $data = json_encode(array( 'apikey' => $api, 'email' => array('email' => 'user@gmail.com'), 'id' => 'uh34jhsd35', 'status' => 'subscribed', 'merge_vars' => array('FNAME'=>'Amit', 'LNAME'=>'Patil') )); |
Make cURL request
12345678910111213141516
if (function_exists('curl_init') && function_exists('curl_setopt')) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $final_url); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); 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, $data); curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); $result = curl_exec($ch); curl_close($ch);} print_r($result);
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
if (function_exists('curl_init') && function_exists('curl_setopt')) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $final_url); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); 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, $data); curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); $result = curl_exec($ch); curl_close($ch); } print_r($result); |
v good!!!!!!!!!!!!