• 1.
    <?php
  • 2.
    function storeAddress(){
  • 3.
    	
  • 4.
    	// Validation
  • 5.
    	if(!$_GET['email']){ return "No email address provided"; }  // You can edit this message how you desire
  • 6.
     
  • 7.
    	if(!preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*$/i", $_GET['email'])) {
  • 8.
    		return "Email address is invalid"; // You can edit this message how you desire
  • 9.
    	}
  • 10.
     
  • 11.
    	require_once('MCAPI.class.php');
  • 12.
    	// grab an API Key from http://admin.mailchimp.com/account/api/
  • 13.
    	$api = new MCAPI('Your API');
  • 14.
    	
  • 15.
    	// Use here the same field tags as in your MailChimp list settings and in index.php file
  • 16.
    	// Check them here: MailChimp – Lists – Select your list – Sign up forms – General forms 
  • 17.
    	// and here: MailChimp – Lists – Select your list – Settings – List fields and *|MERGE|* tags 
  • 18.
    	$merge_vars = Array( 
  • 19.
            'EMAIL' => $_GET['email'],
  • 20.
            'FNAME' => $_GET['fname'],
  • 21.
            'LNAME' => $_GET['lname']
  • 22.
            );
  • 23.
    	
  • 24.
    	// grab your List's Unique Id by going to http://admin.mailchimp.com/lists/
  • 25.
    	// Click the "settings" link for the list - the Unique Id is at the bottom of that page. 
  • 26.
    	$list_id = "Your list ID";
  • 27.
     
  • 28.
    	if($api->listSubscribe($list_id, $_GET['email'], $merge_vars, '') === true) {
  • 29.
    		// It worked!	
  • 30.
    		return 'Success! Check your email to confirm sign up.'; // You can edit this message how you desire
  • 31.
    	}else{
  • 32.
    		// An error ocurred, return error message	
  • 33.
    		return 'Error: ' . $api->errorMessage;
  • 34.
    	}
  • 35.
    	
  • 36.
    }
  • 37.
     
  • 38.
    // If being called via ajax, autorun the function
  • 39.
    if($_GET['ajax']){ echo storeAddress(); }
  • 40.
    ?>
  • 41.
     
<?php function storeAddress(){ // Validation if(!$_GET['email']){ return "No email address provided"; } // You can edit this message how you desire if(!preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*$/i", $_GET['email'])) { return "Email address is invalid"; // You can edit this message how you desire } require_once('MCAPI.class.php'); // grab an API Key from http://admin.mailchimp.com/account/api/ $api = new MCAPI('Your API'); // Use here the same field tags as in your MailChimp list settings and in index.php file // Check them here: MailChimp – Lists – Select your list – Sign up forms – General forms // and here: MailChimp – Lists – Select your list – Settings – List fields and *|MERGE|* tags $merge_vars = Array( 'EMAIL' => $_GET['email'], 'FNAME' => $_GET['fname'], 'LNAME' => $_GET['lname'] ); // grab your List's 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 = "Your list ID"; if($api->listSubscribe($list_id, $_GET['email'], $merge_vars, '') === true) { // It worked! return 'Success! Check your email to confirm sign up.'; // You can edit this message how you desire }else{ // An error ocurred, return error message return 'Error: ' . $api->errorMessage; } } // If being called via ajax, autorun the function if($_GET['ajax']){ echo storeAddress(); } ?>

Copy Code to Clipboard Raw

Sign-in or Create a Free Account.

Snippi uses Twitter or Facebook to register and create accounts. Registration will enable you to keep track of your snippets. We never spam your timeline or wall. Ever.

Sign-in with Facebook Sign-in with Twitter