Latest Code Tutorials

How To Create Newsletter in Laravel

Laravel Newsletter Tutorial


How To Create Newsletter in Laravel is the topic, we will discuss today. In this example, we use laravel 5.6. We use spatie/laravel-newsletter package for creating a newsletter in laravel. MailChimp is an email marketing service which provides us to send newsletters to our subscribers. Top bloggers and marketers use professional email marketing services to send email newsletters. Email newsletters can help your business attach to customers.

Earn a Tech Degree and get the skills like Frontend Development or Javascript Development that can help you to launch a career. Start your free trial

How To Create Newsletter in Laravel

We are going to Configure Laravel Project.

Step 1: Download Laravel Project

Establish  Laravel Project by the typing following command.

composer create-project --prefer-dist laravel/laravel newsletter

Step 2: Install Newsletter Package

First, install Newsletter via the Composer package manager.

composer require spatie/laravel-newsletter                                   

The package will automatically register itself.

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

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

Step 3: Sign Up in MailChimp

First, you sign up in MailChimp. If you have already account then sign in.

Step 4: Get MailChimp API Key And List Id

After successfully sign up or sign we can get api key and list id. So follow this image.

Laravel Newsletter Tutorial

You can see below screen. Then move to Extras >> API keys.

Laravel Newsletter Example

Under the Your API keys section, tick on Create A Key and copy your API key which we want in a minute.


laravel newsletter mailchimp tutorial

After successfully generate api key now we can get list id so follow below image to get list id.


How To Integrate Newsletter in Laravel

Click on List name and defaults, and you get to list id in below image.

How to Generate Newsletter in Laravel

Step 5: Set API Key And List Id in .env file

Next, we set up api key and id in the .env file.



Step 6: Create a view file

Create a file in resources  >>  views  >>   newsletter.blade.php and put this following code in it.

<!-- newsletter.blade.php -->

<!DOCTYPE html>
    <meta charset="utf-8">
    <title>Laravel Newsletter Tutorial With Example</title>
    <link rel="stylesheet" href="{{asset('css/app.css')}}">
    <link href="" rel="stylesheet">    
    <div class="container">
    @if (\Session::has('success'))
      <div class="alert alert-success">
        <p>{{ \Session::get('success') }}</p>
      </div><br />
     @if (\Session::has('failure'))
      <div class="alert alert-danger">
        <p>{{ \Session::get('failure') }}</p>
      </div><br />
      <h2>Laravel Newsletter Tutorial With Example</h2><br/>
      <form method="post" action="{{url('newsletter')}}">
        <div class="row">
          <div class="col-md-4"></div>
            <div class="form-group col-md-2">
              <label for="Email">Email:</label>
              <input type="text" class="form-control" name="email">
        <div class="row">
          <div class="col-md-4"></div>
          <div class="form-group col-md-4">
            <button type="submit" class="btn btn-success">Submit</button>

Step 7: Create a Controller and route

php artisan make:controller NewsletterController                              

It will build a controller file called NewsletterController.php.

Add 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 ');

We register route in a web.php file.


Laravel Newsletter Tutorial with Example

You can see that alert message Thanks For Subscribe then you move to your mail and see the inbox you have to look at below image like mail.

laravel 5.6 newsletter tutorial

Finally, Our How To Create Newsletter in Laravelis over. Thanks for taking.

  1. abdoul says

    i have done all the step you asked me but nothing is happening

    1. Dava says

      use a mailtrap if you’re using localhost

  2. Kolawole says

    Will the package create a database to store the subscribed users?
    How do I send link of a new post to subscribed users

Leave A Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.