To add the wrapper, using PHP, we first need to download the PHP API wrapper from apidocs.mailchimp.com/api/downloads. We only need the file MCAPI.class.php. We will also need our API key and our list ID. Then we can submit an email address in this manner:
[code language=”php”]
<?php
require_once ‘MCAPI.class.php’;
$apikey = ‘YOUR API KEY’;
$listId = ‘YOUR LIST ID’;
$apiUrl = ‘http://api.mailchimp.com/1.3/’;
// create a new api object
$api = new MCAPI($apikey);
// set $merge_vars to null if you have only one input
$merge_vars = null;
if($email !== ”) {
$return_value = $api->listSubscribe( $listId, $email, $merge_vars );
// check for error code
if ($api->errorCode){
echo "<p>Error: $api->errorCode, $api->errorMessage</p>";
} else {
echo ‘<p>Please check your inbox.</p>’;
}
}
?>
[/code]
That is all there is to it. You can download my complete example that uses jQuery and AJAX to pass the email address from an HTML form to a PHP file that calls the API function from GitHub.