How to Dynamically send a newsletter with MailChimp 3.0 via PHP
Just a quick note: I had this post in my draft for a long time but I didn’t share it — I don’t know why :(
Anyways, Let’s get into it.
About an year ago, I received a request from one of my client that his newsletters are failing due to MailChimp has released their update of version 3.0. He himself was a programmer but was unable to get it working. So He wanted me to look at it. I never worked on MailChimp before so I spent a little amount of time to understand it and how it works and all.
So, the job is to create a template on Mailchimp dashboard which can accept HTML code through an API call. We’ll be using PHP in our example here (Because the client’s website was built over PHP too :( ).
Before moving on, First we need to “create a template” labeled as “Code your own” and just add an empty HTML code.
Now you have created a template, now go to this Gist and copy/paste the code. On line# 11 it uses code from MailChimp 3.0 PHP wrapper by Drew McLellan.
Below you may find the preview of the Gist file.
Note: In the code from above gist file, you’ll be need to provide your credentials (so adjust them accordingly) and also provide your HTML code for the template you want to update on Mailchimp.
Hope it helps,
Cheers,
References: