Created
April 8, 2015 21:53
-
-
Save VincentLoy/3a9ad67ed5ef2e655f03 to your computer and use it in GitHub Desktop.
mailchimp.snippet.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Created by PhpStorm. | |
* User: Vincent | |
* Date: 05/04/2015 | |
* Time: 12:46 | |
*/ | |
$apiKey = 'your-api-key'; | |
$listId = 'your-list-id'; | |
$email = $_POST['email']; | |
$email_type = 'html'; | |
$double_optin=false; | |
$send_welcome=false; | |
//replace us2 with your actual datacenter | |
$submit_url = "http://us2.api.mailchimp.com/1.3/?method=listSubscribe"; | |
$data = array( | |
'email_address'=>$email, | |
'apikey'=>$apiKey, | |
'id' => $listId, | |
'double_optin' => $double_optin, | |
'send_welcome' => $send_welcome, | |
'email_type' => $email_type | |
); | |
$payload = json_encode($data); | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_URL, $submit_url); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
curl_setopt($ch, CURLOPT_POST, true); | |
curl_setopt($ch, CURLOPT_POSTFIELDS, urlencode($payload)); | |
$result = curl_exec($ch); | |
curl_close ($ch); | |
$data = json_decode($result); | |
if ($data->error){ | |
echo $data->error; | |
} else { | |
echo "Thank you ! You've been added to our email list."; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment