Created
April 22, 2014 13:02
-
-
Save itsme-renee/11178300 to your computer and use it in GitHub Desktop.
Mail Chimp Api subscribe to list example
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 | |
/** | |
* First things first | |
* | |
* get the mailchimp api php package (you can use composer or just download it) | |
* | |
* https://packagist.org/packages/mailchimp/mailchimp | |
* | |
* Put it somewhere that you can access it and then instantiate it. (see the require_once line) | |
* | |
*/ | |
if(!isset($_POST['email'])){ | |
echo json_encode(array('error' => 'must be a post and expecting [email] param')); | |
exit; | |
} | |
require_once "mailchimp-api-php/src/Mailchimp.php"; | |
try { | |
$mail_chimp = new Mailchimp(''); //api key | |
$list_id = ''; //list id | |
$email = trim($_POST['email']); | |
$result = $mail_chimp->call('lists/subscribe', array('id' => $list_id, 'email' => array('email' => $email),)); | |
if(isset($result['email'])){ | |
echo json_encode(array('success' => 'all is well')); | |
}else{ | |
echo json_encode(array('error' => 'aw man')); | |
} | |
} catch (Exception $e) { | |
echo json_encode(array('error' => 'catchable error')); | |
} | |
exit; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Much neat. So succinct.