Instead of using form provided by MailChimp, we can integrate MailChimp subscription to our website using API. Subscribing users to MailChimp List is quite simple using MailChimp API v3. All you need is a MailChimp Account and a MailChimp List. Here’s the step by step guide to add subscriber with PHP and cURL.
1. Getting MailChimp API Key
First of all you need to log into MailChimp Account. If you haven’t created account yet, it is pretty straight forward to create and get started with MailChimp. Once logged in, click your profile name >> Choose Account >> Extras drop-down >> API key. You will see something like the following screenshot.
If you already have a API key, it will be shown at ‘Your API keys’ section. You can simply note it. If not then click the ‘Create A Key’ button to create new API Key.
2. Creating MailChimp List
Next we need MailChimp List to which we are going to add subscribers using API. If you haven’t created List yet, just click the “Lists” in the navigation menu. Then fill the ‘Create List’ form properly. Now that you have created MailChimp List, it’s time to find the List ID.
To get the List ID, navigate to the Lists page, click the drop-down menu next to the list you want to work with, and then choose Settings. Scroll to find the unique List ID field. The string of letters and numbers is the list ID.
3. Integrating MailChimp API
So far we have gathered MailChimp API key and List ID. Now it’s time to make our hand dirty with coding. Here’s the PHP snippet.
I have used $_GET request as demo to fetch firstname, lastname and email. Instead you can use $_POST or data from database to add subscriber to you newsletter list. And then run this script, check your list. You will find the subscriber add to your list.
In this way, we can add subscriber to MailChimp list. Furthermore, we can dynamically create campaign, add content to the campaign and send newsletter using API. Check this post for more details: Dynamically send MailChimp newsletter via PHP.