MailChimp API Subscribe or Unsubscribe User Using PHP Script

MailChimp is one of the top email marketing services you can use out there, it’s fremium (it offer free and premium services), it allows you to use their skinned html or styled HTML code ready to copy and paste into your site but what if you need something more than their default provided form? Perhaps subscribe user on form submission without them knowing (evil move), this article is intended for those who looking to create custom user subscription or unsubscribe user using PHP script.

This script is handy for people who are looking for one of the following:

  • Marketing: Subscribe user after form submission
  • User engagement: Subscribe user on Ecommerce site registration
  • And more.

What We Need

  • MailChimp PHP API (download here)
    • a. We’ll use this API to connect to MailChimp
  • MailChimp API Key
    • a. Key can be found in your MailChimp Profile Dropdown Menu -> Profile -> Extras -> API Keys
    • b. Click Create A Key button to create a new API Key
    • c. Grab and save the key for later use
  • MailChimp List ID
    a. List ID can be found on your list of created Lists, Lists -> Click Create a List button if you have no List added yet, else, -> Click Dropdown Arrow (right side of each list) -> Settings -> Scroll to the bottom section and you’ll find Unique ID from there (copy and save it for later use)

So now we’re ready, are you?

We will not cover form submission here, so we assume form is submitted already and ready for subscription

Subscribe: PHP Code

Unsubscribe: PHP Code

That’s it happy marketing 🙂

by Ryan Sutana