Create the command artisan command :
php artisan command:make SendNewletterCommand
In the application / commands, edit SendNewletterCommand.php and:
Name your team:
protected $name = 'newsletter:send';
Create your fire () method:
public function fire()
{
foreach(User::all() as $user)
{
Mail::send('emails.newletter', $data, function($message) use ($user)
{
$message->to($user->email, $user->name)->subject('Welcome!');
});
}
}
Register your team in the artisan by editing app / start / artisan.php and adding:
Artisan::add(new SendNewletterCommand);
And add a new command to your crontab:
0 0 * * sun php /your/project/path/artisan newsletter:send
He will send your emails every day at midnight.
source
share