MailChimp Subscribe Form with PHP, jQuery and AJAX (API 3.0)

MailChimp Subscribe Form with PHP, jQuery and AJAX (API 3.0)

By popular demand, I updated my code and posted it as new GitHub repository that utilizes newer MailChimp API 3.0. Please read the tutorial below to create AJAX based MailChimp subscribe form on your PHP website with a little jQuery knowledge.

Original post using (older and no longer supported) MailChimp API 1.0 can be found here.

What this code does

  • Validate field contents
  • Pass the form submission to MailChimp and add the record to your list
  • Basic fallback method for very, very old browser or does not have JavaScript activated
  • Very customizable and easily expandable, depending on your requirements
  • jQuery and jQuery Validation plugin called from CDNJS to keep number of files to maintain at minimal


  1. jQuery
  2. jQuery Validation Plugin
  3. MailChimp API v3 PHP Wrapper

MailChimp API Key and List ID

Below we start, we need to generate public API key from your MailChimp account and also identify your list ID. If you are not sure how to retrieve those, follow these links from MailChimp Knowledge Base to retrieve your account’s API key and find your list ID.

The Form Page (index.php)

jQuery will handle the AJAX using $.post  method and jQuery Validation plugin will validate the field values including email address format.

For this example, I am including first name and last name as part of the form fields. Feel free to make adjustments as required. Although keep in mind after changing the form fields, you may also need to adjust the subscribe.php  file too.

Form Processor (subscribe.php)

I try to include as much comment as possible to make the code self explanatory.


Click here to download the basic files to create MailChimp subscribe form on your website. Alternatively, you can also visit the GitHub repository.

Coming Soon Templates

The MailChimp subscribe form example only includes basic HTML page. If you are thinking of using it for your upcoming site, and you have limited resources to create the page design, check out my list of 5 Clean and Free Coming Soon Page Templates and Coming Soon & Under Construction Templates on ThemeForest.

14 Comments MailChimp Subscribe Form with PHP, jQuery and AJAX (API 3.0)

  1. Rebecca

    Hello, thanks for sharing this. It works great! Is there a way to load the ‘#response’ back onto the parent page (index.php) without a refresh? Your help will be ecstatically appreciated!

    1. Michael

      Hi Rebecca – If you set the AJAX correctly, then the response message should be loaded on the parent page without a refresh. Unless you are referring to a different behavior.

    1. Michael

      It’s quite hard to determine the problem without having access to the code. The only advice I can give for now is to try looking at your MailChimp API calls history/log. It is under Account > Extras > API Keys.

  2. Asti

    Hi, really like your explainations, Thank you. I would like to add a double Opt-in. Could you guide me to add it? It would be great! Thanks again.

    1. Michael

      Hi, it’s actually quite simple to enable double opt-in. Just change the status array when posting the email address to pending instead of subscribed.
      'status' => 'pending'

  3. Fredrik

    I get the error message
    Parse error: syntax error, unexpected ‘[‘ in /home/xxx/public_html/xxx/mailchimp/subscribe.php on line 16
    How can this be solved?

  4. doudou

    Hi, very great work you have done here, However I would like to know how can we Clear all input fields after submission of data? and how can we display error message inside every inputs ?

    Thanks in advance


Leave a Reply