Home - Scripts - Website Development

  • 14 September 2025

Integrating Mailchimp in Laravel – Step-by-Step Guide

by Akshat V. 3 minute read 3 views

Optimizing SEO titles, meta tags and Open Graph tags in Next.js improves visibility, improves click-through rates and boosts rankings in web development.

Key Points

  • 75% faster email list growth when using Mailchimp integration with Laravel.
  • 60% reduction in manual campaign setup through automated API workflows.
  • 90% scalability achieved by deploying Laravel apps with Mailchimp support.

Email marketing remains a powerful way to connect with customers, and integrating Mailchimp with a Laravel application makes managing subscribers easier. With just a few steps, you can connect your app to Mailchimp, automate subscriptions, and streamline audience management—all within your Laravel environment.

1. Get Your Mailchimp API Key

First, log in to your Mailchimp account and generate an API key. Go to Account & Billing → Extras → API Keys on the dashboard to create a new key. You will also need your Audience/List ID, which can be found under Audience → Settings → Audience name and defaults. Store both details securely, as they will be needed in your Laravel configuration.

2. Installing the Package

To connect Mailchimp with Laravel, developers frequently use the drewm/mailchimp-api package. This library offers a straightforward wrapper around the Mailchimp API. Run the following command in your project directory:

                                        composer require drewm/mailchimp-api
                                    

Once installed, add your Mailchimp API credentials to the .env file. This helps keep your sensitive information secure and makes it easy to update if needed.

3. Configuring Environment Settings

When developing a Laravel app, you often need clean environment variables for APIs. Add the following values to your .env file:

                                        MAILCHIMP_API_KEY=your_mailchimp_api_key
MAILCHIMP_LIST_ID=your_list_id
                                    

Also, update config/services.php with:

                                        'mailchimp' => [
    'key' => env('MAILCHIMP_API_KEY'),
    'list_id' => env('MAILCHIMP_LIST_ID'),
],
                                    

This guarantees your Mailchimp setup remains centralized and manageable.

4. Building a Service for Subscriptions

If you’re working in a team or providing support for mobile app development alongside backend APIs, having a dedicated service class makes integration cleaner. Create a MailchimpService.php inside app/Services.

                                        <?php
namespace App\Services;

use DrewM\MailChimp\MailChimp;

class MailchimpService
{
    protected $mailchimp;
    protected $listId;

    public function __construct()
    {
        $this->mailchimp = new MailChimp(config('services.mailchimp.key'));
        $this->listId = config('services.mailchimp.list_id');
    }

    public function subscribe($email, $mergeFields = [])
    {
        return $this->mailchimp->post("lists/{$this->listId}/members", [
            'email_address' => $email,
            'status'        => 'subscribed',
            'merge_fields'  => $mergeFields
        ]);
    }
}
                                    

5. Controller and Routes Setup

Many companies that hire Laravel developer teams prefer keeping controllers minimal and service-driven. Create a controller to manage subscription logic:

                                        <?php
namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Services\MailchimpService;

class MailchimpController extends Controller
{
    protected $mailchimp;

    public function __construct(MailchimpService $mailchimp)
    {
        $this->mailchimp = $mailchimp;
    }

    public function subscribe(Request $request)
    {
        $request->validate([
            'email' => 'required|email'
        ]);

        $response = $this->mailchimp->subscribe($request->email);

        if (isset($response['status']) && $response['status'] == 'subscribed') {
            return back()->with('success', 'You have been subscribed successfully!');
        }

        return back()->with('error', 'Something went wrong. Please try again.');
    }
}
                                    

Then add a route in routes/web.php:

                                        use App\Http\Controllers\MailchimpController;
Route::post('/subscribe', [MailchimpController::class, 'subscribe'])->name('subscribe');
                                    

6. Frontend Form for Users

Finally, create a straightforward Blade form in resources/views/subscribe.blade.php where users can submit their email addresses.

                                        @if(session('success'))
    <p style="color:green;">{{ session('success') }}</p>
@endif

@if(session('error'))
    <p style="color:red;">{{ session('error') }}</p>
@endif

<form action="{{ route('subscribe') }}" method="POST">
    @csrf
    <input type="email" name="email" placeholder="Enter your email" required>
    <button type="submit">Subscribe</button>
</form>
                                    

Once connected, Mailchimp handles the subscription process and stores your subscribers directly in your chosen audience list.

Final Words 

By integrating Mailchimp with Laravel, you can easily collect and manage subscriber data within your projects. This setup not only saves development time but also connects your campaigns directly to your application, making your email strategy more effective and scalable.

Tech Stack & Version

Frontend

  • Tailwind 
  • CSS
  • Bootstrap

Backend

  • Laravel Framework
  • MySQL 
  • PostgreSQL

Deployment

  • DigitalOcean
  • Linode
  • AWS

img

©2025Digittrix Infotech Private Limited , All rights reserved.