Hey there, If you are building something interesting and looking to send bulk emails using your application's in-built power provided by Laravel itself. You can do that easily.
You can use SMTP or...
Gurpreet Kait
Author
Hey there, If you are building something interesting and looking to send bulk emails using your application's in-built power provided by Laravel itself. You can do that easily.
You can use SMTP or external services like Mailgun or Sendgrid as well.
In this blog, I'll walk through the process step-by-step, and I'll provide example code snippets along the way.
Prerequisites
Installation
Make sure you have a laravel application up and running.
In my case, I have seeded a few emails to perform the bulk email action. But in your case, you may be uploading via CSV or you may be just entering them in the tables manually. But at the end when we have emails in the db the case is the same to send them.
// it will generate table for queued jobs
php artisan queue:table
// migrate
php artisan migrate
Schedule the Email Sending Task
Now, let's set up the Laravel scheduler to run the email-sending task periodically. Edit the app/Console/Kernel.php file and add the following code to the schedule method:
// app/Console/Kernel.php
use App\Console\Commands\SendBulkEmails;
protected function schedule(Schedule $schedule): void
{
// $schedule->command('inspire')->hourly();
$schedule->command('app:send-bulk-emails')->dailyAt('16:41');
}
Perform
Now, you can run the below command to test the whole process.
php artisan queue:listen
That's it! You have set up a scheduled task to send bulk emails in the background using Laravel's task scheduling and the queue system. Make sure to customize the code and configuration according to your specific needs and requirements.