I want to bulk send emails to many (around 300-600) mails using laravel scheduler, for this purpose I created a command to run along with laravel's task scheduler.
As for my mail API, I'm using laravel's integratin of the Mailgun API, Mailgun lets you send thoushands of them.
I also want to run the mail sending through a queue, afaik using a queue is specially for performance heavy tasks such as sending mail.
As for my questions, is this a good, performant way to send multiple mails with laravel scheduler?
Will each of my mails be properly sent to the queue for dispatching?
When I run php artisan schedule:run òn my local dev machine (Windws) I get the following message:
C:\xampp\htdocs\dtcburger.com>php artisan schedule:run
Running scheduled command: "C:\xampp\php\php.exe" "artisan" App\Console\SendWeeklyMail1 > "NUL" 2>&1
But nothing happens after that, I haven't received any emails.
My command for sending mails:
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Mail;
use App\Models\Event;
use App\Models\Discount;
use App\Models\General;
use App\Models\Sub;
use App\Mail\weekly\WeeklyMail1;
class SendWeeklyMail1 extends Command
{
protected $signature = 'emails:weekly';
protected $description = "What's new this week? send weekly emails to subbed users";
public function __construct()
{
parent::__construct();
}
public function handle()
{
$emails = [ 'zipizape@gmail.com', 'zipizape@gmail.com', 'zipizape@gmail.com',
'zipizape@gmail.com', 'zipizape@gmail.com', 'zipizape@gmail.com',
'zipizape@gmail.com', 'zipizape@gmail.com', 'zipizape@gmail.com',
'zipizape@gmail.com', 'zipizape@gmail.com', 'zipizape@gmail.com',
'zipizape@gmail.com', 'zipizape@gmail.com', 'zipizape@gmail.com',
'zipizape@gmail.com', 'zipizape@gmail.com', 'zipizape@gmail.com' ];
$mailData = [
'subject' => 'Últimas novedades en '.env('APP_NAME'),
'events' => $events,
'discounts' => $discounts,
];
foreach ($emails as $email)
{
Mail::to( $email )->queue(new WeeklyMail1($mailData));
};
}
}
Kernel file:
protected $commands = [
'App\Console\Commands\SendWeeklyMail1',
'App\Console\Commands\SendBulletinMail1',
];
protected function schedule(Schedule $schedule)
{
$schedule->command(SendWeeklyMail1::class);
}