Mailchimp API v3 and Brevo integration with AJAX subscription forms, double opt-in, GDPR compliance, and automated new-post notifications.
Why Email Still Matters
Social media algorithms change monthly. SEO rankings fluctuate. But an email list is yours — no algorithm decides whether your subscribers see your content. For our client blogs, email drives 15-25% of return traffic, second only to organic search.
Mailchimp Integration
JekCMS integrates with Mailchimp API v3 for list management. The subscribe endpoint handles both new subscriptions and tag management:
function subscribeToMailchimp(string $email, string $listId, array $tags = []): array
{
$apiKey = get_setting('mailchimp_api_key');
$dc = substr($apiKey, strpos($apiKey, '-') + 1); // Extract data center
$subscriberHash = md5(strtolower($email));
$url = "https://{$dc}.api.mailchimp.com/3.0/lists/{$listId}/members/{$subscriberHash}";
$data = [
'email_address' => $email,
'status_if_new' => 'pending', // Double opt-in
'status' => 'subscribed',
'tags' => $tags,
];
$ch = curl_init($url);
curl_setopt_array($ch, [
CURLOPT_CUSTOMREQUEST => 'PUT', // PUT = create or update
CURLOPT_POSTFIELDS => json_encode($data),
CURLOPT_HTTPHEADER => [
'Authorization: apikey ' . $apiKey,
'Content-Type: application/json',
],
CURLOPT_RETURNTRANSFER => true,
]);
$response = json_decode(curl_exec($ch), true);
curl_close($ch);
return $response;
}
AJAX Subscription Form
<form class="newsletter-form" data-action="/api/v1/subscribe">
<input type="email" name="email" placeholder="you@example.com" required>
<label><input type="checkbox" name="consent" required>
I agree to receive email newsletters. You can unsubscribe anytime.
</label>
<button type="submit">Subscribe</button>
<div class="form-message"></div>
</form>
The form submits via AJAX with a CSRF token. The response message appears inline without a page reload. On success, the form is replaced with a "Check your inbox to confirm" message (for double opt-in).
GDPR Compliance
- Explicit consent checkbox — not pre-checked, clearly worded
- Double opt-in — subscriber must confirm via email before receiving newsletters
- Easy unsubscribe — every email includes a one-click unsubscribe link
- Data export/delete — admin can export or delete a subscriber's data on request
New Post Notification Workflow
When a new post is published, an automated email goes to subscribers. We use n8n to orchestrate this: JekCMS webhook fires on publish → n8n creates the email template with post title, excerpt, and featured image → sends via Mailchimp campaign API or Brevo transactional email.
The email template is minimalist: post title as heading, 2-3 sentence excerpt, featured image, and a single "Read more" button. No sidebar, no multiple CTAs. Open rate: 28-35% (industry average is 21%).