profile.jpg

Aditya Pratama

DevOps | SRE | Cloud Engineer
Return to Blog List

How to Create a Newsletter Subscribers with Laravel

August 9, 2022

This is my way of how to create or manage an easy and free internal Subscribers Newsletter with Laravel to send email notifications to the subscriber list about new content on the blog.adityacprtm.com site before switching to wordpress.

Subscribe_x_Laravel.jpg

This blog is part of Packages that I use to build my Personal Blog with Laravel series

This is my way of how to create or manage an easy and free internal Subscribers Newsletter with Laravel to send email notifications to the subscriber list about new content on the blog.adityacprtm.com site before switching to wordpress.

update: the blog switches to adityacprtm.dev/blog or dev.to/adityacprtm

Another solution is to use a Newsletter Subscription provider such as MailChimp. But if you don't want to use a third party to store your Subscriber data, you can create your own with laravel using the package from mydnic/laravel-subscribers.

Installation

It is assumed that you have a laravel project ready.

We can use Composer to install, the packages will be installed automatically

composer require mydnic/laravel-subscribers

Then do a publish migration:

php artisan vendor:publish --provider=""Mydnic\Subscribers\SubscribersServiceProvider"" --tag=""subscribers-migrations""

How to Use Newsletter Subscribers

We only need to create a form, then customize it:

<form action=""{{ route('subscribers.store') }}"" method=""post"">
    @csrf
    <input type=""email"" name=""email"">
    <input type=""submit"" value=""submit"">
</form>
@if (session('subscribed'))
    <div class=""alert alert-success"">
        {{ session('subscribed') }}
    </div>
@endif

Unsubscribe or Delete

Just give this link to subscribers:

<a href=""{{ route('subscribers.delete', ['email' => $subscriber->email]) }}"">unsubscribe</a>

This line will generate a link like: /subscribers/[email protected]


That's it! Next, prepare a template for the email.

0 Comments