Super Simple Laravel Newsletter Subscribers System
If you're building a website where you create content, or where your users post content (like a job board or something), then sometimes you might want to send an email to a list of users to let them know new content is available.
An easy solution would be use Mailchimp or any other newsletter service provider.
But now you want to simply generate a simple HTML view and send this view by email. And using those newsletter provider is often not easy.
So what you need is actually a table in your database where you very simply list email addresses of the users that want to subscribe to your newsletter.
Then you create a Scheduled Command that will trigger a job to actually send a automated email to all those email addresses.
And if, like me, you're building new projects every month, you probably want to implement this same table of "subscribers" into all your projects.
This is where my package mydnic/laravel-subscribers will help you!
Pulling this package in your project will instantly provide you a Subscriber
model, with the corresponding table.
All you need to do is to put a simple form into your template. The code for this form is also provided.
You may use Composer to Install Laravel Subscribers:
composer require mydnic/laravel-subscribers
The package will automatically register itself
You then must publish the migration with:
php artisan vendor:publish --provider="Mydnic\Subscribers\SubscribersServiceProvider" --tag="subscribers-migrations"
In your view, you simply need to add a form that you can customize the way you want
<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
Simply provide this link to your subscribers:
<a href="{{ route('subscribers.delete', ['email' => $subscriber->email]) }}">unsubscribe</a>
This will generate a link like /subscribers/[email protected]
Now you have everything you need!
All you need to do is to build your email template and send it to your subscribers!
I consider myself as an IT Business Artisan. Or Consultant CTO. I'm a self-taught Web Developper, coach and teacher. My main work is helping and guiding digital startups.
more about meBTC
18SY81ejLGFuJ9KMWQu5zPrDGuR5rDiauM
ETH
0x519e0eaa9bc83018bb306880548b79fc0794cd08
XMR
895bSneY4eoZjsr2hN2CAALkUrMExHEV5Pbg8TJb6ejnMLN7js1gLAXQySqbSbfzjWHQpQhQpvFtojbkdZQZmM9qCFz7BXU
2024 © My Dynamic Production SRL All rights Reserved.