How To Integrate Mailchimp API In Laravel 9

Websolutionstuff | Aug-01-2022 | Categories : Laravel

In this article, we will see how to integrate mailchimp API in laravel 9. Here we will learn how we can integrate Mailchimp API into our laravel 9 application. Mailchimp provides us manage subscribers, send emails by using campaigns and also track the email results, etc. By using Mailchimp we can track how many subscribers are open to email and read.

We will also use skovmand/mailchimp-laravel laravel package for mailchimp API in the laravel 9 application. A minimal service provider to set up and use the Mailchimp API v2 PHP library in Laravel.

So, let's see mailchimp integration in laravel 9 or laravel 9 mailchimp API integration.

Step 1: Create Mailchimp Account

In this step, we will create a new account from here: Create New Account. You have to create a new list, click on Lists on the menu and create a new list. After creating successful lists then select your list, go to settings->List name and defaults and copy your list id, we will use it on API.

Now, we can get API Key so click here and get the API key: API Key

Open your .env file and paste it in the .env file.






Step 2: Install Mailchimp Package

Now, will install mailchimp package using the composer command.

composer require skovmand/mailchimp-laravel


Step 3: Install The Newsletter Package

After installing mailchimp, we will install the news-letter package using the composer command.

composer require spatie/laravel-newsletter

To publish the config file to config/newsletter.php run:

php artisan vendor:publish --provider="Spatie\Newsletter\NewsletterServiceProvider"




In this step, we will use mailchimp API key and list ID in the config/newsletter.php file

return [
* The driver to use to interact with MailChimp API.
* You may use "log" or "null" to prevent calling the
* API directly from your environment.
'driver' => env('MAILCHIMP_DRIVER', 'api'),
* The API key of a MailChimp account. You can find yours at
'apiKey' => env('MAILCHIMP_APIKEY'),
* The listName to use when no listName has been specified in a method.
'defaultListName' => 'subscribers',
* Here you can define properties of the lists.
'lists' => [
* This key is used to identify this list. It can be used
* as the listName parameter provided in the various methods.
* You can set it to any string you want and you can add
* as many lists as you want.
'subscribers' => [
* A MailChimp list id. Check the MailChimp docs if you don't know
* how to get this value:
'id' => env('MAILCHIMP_LIST_ID'),
* The GDPR marketing permissions of this audience.
* You can get a list of your permissions with this command: "php artisan newsletter:permissions"
'marketing_permissions' => [
// 'email' => '',
// 'customized_online_advertising' => '',
* If you're having trouble with https connections, set this to false.
'ssl' => true,


Step 5: Create a NewsletterController

Now, we will create a controller using the below command.

php artisan make:controller NewsletterController

And add the following code to the controller.


namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Newsletter;

class NewsletterController extends Controller
    public function create()
        return view('newsletter');

    public function store(Request $request)
        if (!Newsletter::isSubscribed($request->email) ) 
            return redirect('newsletter')->with('success', 'Thanks For Subscribe');
        return redirect('newsletter')->with('failure', 'Sorry! You have already subscribed ');



Step 6: Create a blade file

In this step, we will create a blade file for view display.


<h2 class="text-center">How To Integrate Mailchimp API In Laravel 9 - Websolutionstuff</h2>
<div class="container">
@if ($message = Session::get('success'))
<div class="alert alert-success alert-block">
<button type="button" class="close" data-dismiss="alert">×</button>
<strong>{{ $message }}</strong>
@if ($message = Session::get('error'))
<div class="alert alert-danger alert-block">
<button type="button" class="close" data-dismiss="alert">×</button>
<strong>{{ $message }}</strong>
<div class="row">
<div class="col-md-5">
<div class="well">
{!! Form::open(array('route' => 'subscribe')) !!}
<h3 class="text-center">Subscribe Your Email</h3>
<input class="form-control" name="email" id="email" type="email" placeholder="Your Email" required>
<div class="text-center">
<button class="btn btn-info btn-lg" type="submit">Subscribe</button>
{!! Form::close() !!}


Step 7: Add routes

Add route in web.php file



You might also like:

Recommended Post
Featured Post
How to Search Object by ID and Remove It from JSON Array In JavaScript
How to Search Object by ID and...

In this example we will see how to search object by id and remove it from json array in javascript. we need to add ...

Read More


Laravel 8 Class NumberFormatter Not Found
Laravel 8 Class NumberFormatte...

In this example we will see example of laravel 8 class numberformatter not found. For numberformatter we need PHP 5...

Read More


How To Fixed Header In Datatable Using jQuery
How To Fixed Header In Datatab...

Data presentation and organization are easier with data tables. They help display information in an organized way. These...

Read More


How to Run Specific Seeder in Laravel 8
How to Run Specific Seeder in...

In this example, we will learn how to run a specific seeder in laravel 8. If you want to run only one seeder in laravel...

Read More