Send scheduled emails in Laravel

Laravel Mail Scheduler is a package that helps you to send emails in batches.

Send scheduled emails in Laravel

Laravel Mail Scheduler is a package that helps you to send emails in batches. This is helpful when you need to send hundred emails at once, the emails are stacked in database and will be sent in batches.

You may stack a new mail using the facade ScheduledEmail.

For security reasons, you may want to encrypt the mailable data in the database. The api provides an encrypted method.
<?php

use App\Mail\CustomerEmail;
use Oneduo\MailScheduler\Support\Facades\ScheduledEmail;

$mailable = new CustomerEmail();

ScheduledEmail::mailable($mailable)
    ->to(['john@doe.com'])
    ->encrypted()
    ->save();

By default the package automatically register a task into the scheduler to send emails every five minutes. You may change the cron expression with the MAIL_SCHEDULER_SCHEDULE_CRON environment variable or disable the auto schedule feature to create the task yourself.

<?php

namespace App\Console;

use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;

class Kernel extends ConsoleKernel
{
    /**
     * Define the application's command schedule.
     *
     * @param  \Illuminate\Console\Scheduling\Schedule  $schedule
     * @return void
     */
    protected function schedule(Schedule $schedule)
    {
        $schedule->command('mail-scheduler:send')
            ->everyMinute()
            ->between('08:00', '18:00');
    }

    /**
     * Register the commands for the application.
     *
     * @return void
     */
    protected function commands()
    {
        $this->load(__DIR__.'/Commands');

        require base_path('routes/console.php');
    }
}

To learn more about this package and get full installation instructions, check out the laravel-mail-scheduler on GitHub.