• rss icon


Create a Single Opt-In MailChimp Form

MailChimp™ is a popular email marketing service. It allows its members to embed forms to collect email addressed through their websites. But to discourage the practice sending spam emails, MailChimp makes double opt-in mandatory on their embedded forms. But by utilizing MailChimp’s API members are able to create single opt-in MailChip forms. This simply requires the use of an API wrapper.

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:

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>';

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.