You must use server-side code to protect your MailChimp account.
Below is an updated version of this answer that uses PHP :
PHP files are "protected" on a server where the user never sees them, but jQuery can still use and use.
1) Download the PHP 5 jQuery example here ...
http://apidocs.mailchimp.com/downloads/mcapi-simple-subscribe-jquery.zip
If you have only PHP 4, just download MCAPI version 1.2 and replace the corresponding MCAPI.class.php file above.
http://apidocs.mailchimp.com/downloads/mailchimp-api-class-1-2.zip
2) Follow the instructions in the Readme file by adding the API key and list identifier to the store-address.php in the appropriate places.
3) You may also want to collect a username and / or other information. You must add the array to the store-address.php file using the appropriate Merge variables.
This is what my store-address.php file looks like, where I also collect the first name, last name and email type:
<?php function storeAddress(){ require_once('MCAPI.class.php'); // same directory as store-address.php // grab an API Key from http://admin.mailchimp.com/account/api/ $api = new MCAPI('123456789-us2'); $merge_vars = Array( 'EMAIL' => $_GET['email'], 'FNAME' => $_GET['fname'], 'LNAME' => $_GET['lname'] ); // grab your List Unique Id by going to http://admin.mailchimp.com/lists/ // Click the "settings" link for the list - the Unique Id is at the bottom of that page. $list_id = "123456a"; if($api->listSubscribe($list_id, $_GET['email'], $merge_vars , $_GET['emailtype']) === true) { // It worked! return 'Success! Check your inbox or spam folder for a message containing a confirmation link.'; }else{ // An error ocurred, return error message return '<b>Error:</b> ' . $api->errorMessage; } } // If being called via ajax, autorun the function if($_GET['ajax']){ echo storeAddress(); } ?>
4) Create your HTML / CSS / jQuery form. This does not have to be on a PHP page.
Here is something like my index.html file:
<form id="signup" action="index.html" method="get"> <input type="hidden" name="ajax" value="true" /> First Name: <input type="text" name="fname" id="fname" /> Last Name: <input type="text" name="lname" id="lname" /> email Address (required): <input type="email" name="email" id="email" /> HTML: <input type="radio" name="emailtype" value="html" checked="checked" /> Text: <input type="radio" name="emailtype" value="text" /> <input type="submit" id="SendButton" name="submit" value="Submit" /> </form> <div id="message"></div> <script src="jquery.min.js" type="text/javascript"></script> <script type="text/javascript"> $(document).ready(function() { $('#signup').submit(function() { $("#message").html("<span class='error'>Adding your email address...</span>"); $.ajax({ url: 'inc/store-address.php', </script>
Required Fragments ...
index.html , built both above and similar. With jQuery, the look and feel are endless.
store-address.php file downloaded as part of the PHP examples at the Mailchimp website and modified using the KEY API and LIST ID . You need to add other additional fields to the array.
The MCAPI.class.php file downloaded from the Mailchimp website (version 1.3 for PHP 5 or version 1.2 for PHP 4). Put it in the same directory as your store-address.php , or you must update the url in store-address.php so that it can find it.