About Manage Mailchimp Subscription
A lightweight module to subscribe, update, unsubscribe and delete users from lists in Mailchimp
|Category 1||Social, Feeds, Services|
Modules that provide or work with social networking services and/or external feeds.
|Category 2||Other Modules|
Modules that have a unique purpose not covered by existing categories.
Close to stable, but users are advised to be cautious and test thoroughly.*
|Date Added||April 24, 2018|
|Last Updated||May 27, 2018|
This module's files should be placed in /site/modules/SubscribeToMailchimp/
How to install or uninstall modules
Lightweight module for ProcessWire that let you subscribe a user to a mailchimp list.
I have only tested it with PHP7.x and Processwire 3.x.
// Easily subscribe a user with SubscribeToMailchimp $mc = $modules->get("SubscribeToMailchimp"); $mc->subscribe('firstname.lastname@example.org');
- Download the zip file at Github or clone directly the repo into your
- If you downloaded the
zip file, extract it in your
- You might have to change the folders name to 'SubscribeToMailchimp'.
- Goto the modules admin page, click on refresh and install it.
- Log into your Mailchimp account and go to
Profile > Extras > API Keys.
- If you don't have an API Key, create a new one.
- Copy your API Key and paste it in the module settings (
Processwire > Modules > Site > SubscribeToMailchimp).
- Back in Mailchimp, go to the list, where you want your new subscribers.
- Go to
Settings > List name and defaults. Copy the List ID an paste it into the module settings.
- Test your settings with the provided checkbox.
// load module into template $mc = $modules->get("SubscribeToMailchimp"); // subscribe / update a user in your default list $mc->subscribe('email@example.com'); // add merge_fields to fill out user data, based on your list MERGE_FIELD options // You need to setup the fields at "Settings > List fields and *|MERGE|* tags" first! $mc->subscribe('firstname.lastname@example.org', ['FNAME' => 'John', 'LNAME' => 'Doe']); // Subscribe a user to a custom list (other than default) $mc->subscribe('email@example.com', ['FNAME' => 'John', 'LNAME' => 'Doe'], 'adcdef12345'); // Work with additional parameters (not merge_field values!) $mc->subscribe('firstname.lastname@example.org', NULL, NULL, [ 'language' => 'en', // find language list here: https://kb.mailchimp.com/lists/manage-contacts/view-and-edit-contact-languages#Language-Codes 'vip' => true, // boolean vip status 'location' => [ // geo location based on lat/log coordinates 'latitude' => '48.8722344', 'longitude', => '2.7736192' ], 'interests' => [ // subscribe user to interest categories / groups based on group id '32fec3561e' => true, '63mel4395m' => false ] ]);
// Unsubscribe a user $mc->unsubscribe('email@example.com'); // Unsubscribe a user from a custom list $mc->unsubscribe('firstname.lastname@example.org', 'abcdef1356'); // Permanently delete a user. Carefully, this step cannot be undone! $mc->delete('email@example.com'); // Get the subscription status of a user. $mc->getStatus('firstname.lastname@example.org'); // Static function to test your settings. // If no list id is provided, it will test your default list and returns a formated html result $mc->testSettings('list id');
- This module does not do any data validation. Use a sever-sided validation like Valitron
- Make sure that you have set up your fields in your Mailchimp list. You can do it at
Settings > List fields and *|MERGE|* tags
Example usage after a form is submitted on your page:
// ... validation of form data $mc = $modules->get("SubscribeToMailchimp"); $email = $input->post->email; $subscriber = [ 'FNAME' => $input->post->firstname, 'LNAME' => $input->post->lastname, ]; $mc->subscribe($email, $subscriber);
In case of trouble check your ProcessWire warning logs.
If you have enabled double opt-in (it is enabled by default) you will not see the subscriber, until he confirmed the subscription in the email sent by Mailchimp
- Check if you have the right List ID and API Key.
- Check if you pass fields, that exist in your list.
- Check if you pass a valid email address.
Go to Mailchimps Error Glossary for more Information
Until now, you can update from every version without changing your code
- #6: Fixed a bug, where you couldn't use the 'ADDRESS' merge field and removed more unused lines - Big thanks to @ml-eds for the quick fix!
- #4: Deleted unused line
#2: Added getStatus method
$mc->getStatus($email, $list = "")
#2: Added ability to resubscribe a user, if he has unsubscribed. The user will have to confirm his subscription again via double-opt-in (if not disabled)
Centralized the validation warning via a constant
Updated the getApiBase to be more flexible with different API calls
- Added 'Unsubscribe' method
$mc->unsubscribe($email, $list = "")
- Added 'Delete' method
$mc->delete($email, $list = "")
- Removed type declarations to be compatible with PHP 5.1* (thanks to wbmnfktr)
- Changed the way, the base url for the api gets called
*I have only tested it with PHP 7.x so far, so use on owners risk :)
Any suggestions? Join the Discussion in the ProcessWire Forums or contribute directly on Github.
No comments yet. Be the first to post!
Your e-mail is kept confidential and not included with your comment. Website is optional.
- Admin Helpers
- Core Modules
- Development Tools
- Field Types
- Input Fields
- Language Modules
- Language Packs
- Markup Generation
- Premium Modules
- Process Modules
- Proof of Concept
- Site Profiles
- Social, Feeds, Services
- Text Formatters
- Other Modules
- Users and Access
*Use modules at your own risk. There are no guarantees or warranties. It is recommended that you backup your site and database before installing new modules.