Mailchimp Integration
Subscribe an email address to a Mailchimp list when a form is submitted. Requires the MC4WP (Mailchimp for WordPress) plugin.
Action type: mailchimp
Class: Core_Forms\Actions\MailChimp
Source: src/actions/class-mailchimp.php
Prerequisites
This integration requires the MC4WP - Mailchimp for WordPress plugin to be installed and connected to your Mailchimp account.
- Install and activate the MC4WP plugin.
- Go to MC4WP > Mailchimp and connect your Mailchimp API key.
- Ensure your lists are synced.
Setup
- In WordPress, edit your form > Actions tab > Add Action > Mailchimp.
- Select the Mailchimp list from the dropdown.
If no lists appear, click the link to connect your Mailchimp account in the MC4WP settings first.
Settings Reference
| Setting | Required | Default | Description |
|---|---|---|---|
| List | Yes | -- | Mailchimp audience/list to subscribe to (dropdown from MC4WP) |
Email Detection
The integration automatically finds the email address in the submission data. It scans all submitted fields and uses the first value that passes is_email() validation. No explicit email field mapping is needed.
Subscriber Status
New subscribers are added with pending status, meaning they will receive a double opt-in confirmation email from Mailchimp before being fully subscribed.
Merge Fields
Custom merge fields can be added via the cf_mailchimp_action_merge_fields filter:
add_filter( 'cf_mailchimp_action_merge_fields', function( $merge_fields, $submission, $form ) {
$merge_fields['FNAME'] = $submission->data['first_name'] ?? '';
$merge_fields['LNAME'] = $submission->data['last_name'] ?? '';
return $merge_fields;
}, 10, 3 );
Subscriber Data
The full subscriber data array can be modified via the cf_mailchimp_action_subscriber_data filter:
add_filter( 'cf_mailchimp_action_subscriber_data', function( $data, $submission, $form ) {
$data['status'] = 'subscribed'; // Skip double opt-in
$data['tags'] = [ 'website-lead' ];
return $data;
}, 10, 3 );
Error Logging
Errors are logged via the MC4WP debug log (mc4wp_get_debug_log()):
- Already subscribed (error code 214): logged as a warning
- Other API errors: logged as errors
- Successful subscriptions: logged as info
View logs at MC4WP > Other > Debug Log.
How It Works
- Scans all submitted fields for a valid email address.
- If no email is found, the action silently returns.
- Applies the
cf_mailchimp_action_merge_fieldsfilter for custom merge fields. - Applies the
cf_mailchimp_action_subscriber_datafilter for full data control. - Calls
MC4WP_MailChimp::list_subscribe()with the list ID, email, and data. - Logs the result to the MC4WP debug log.
Troubleshooting
- "Please connect your Mailchimp account first": Install and configure the MC4WP plugin before using this action.
- No lists in dropdown: Go to MC4WP settings and refresh the list cache.
- Subscriber not appearing: Check if double opt-in is enabled (default). The subscriber must confirm via email.
- Already subscribed: This is logged as a warning, not an error. The subscriber already exists on the list.