'Sending mails everyday using schedulers in Laravel
I am not receiving any email. Please help me out. I have changed the environment properly.
use App\User;
use App\Mail\NotifyEmail;
class Notify extends Command
{
protected $signature = 'notify:email';
protected $description = 'Send an email to all the users everyday';
public function handle()
{
$emails = User::pluck('email')->toArray();
$data = ['title' => 'programming' , 'body' => 'php'];
foreach($emails as $email){
Mail::To($email) ->send(new NotifyEmail($data));
}
}
}
My kernel.php has :
$schedule->command('notify:email') ->daily();
App\Mail\NotifyEmail.php :
class NotifyEmail extends Mailable
{
use Queueable, SerializesModels;
public $details;
public function __construct($data)
{
$this -> details = $data;
}
public function build()
{
return $this->view('mail', compact(varname: 'details'));
}
}
mail.blade.php contains {{$details['title']}} and {{$details['body']}}.
Solution 1:[1]
If it is a Queueable, you will need a separate process to run the queue continuously. Without that process, the queue entries just stack up and never get processed. See the Laravel Queue documentation https://laravel.com/docs/9.x/queues#running-the-queue-worker about running queues and/or run artisan queue:work
Solution 2:[2]
have you setup the cron job in crontab? if not nothing would run
read https://laravel.com/docs/8.x/scheduling#running-the-scheduler
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Michiel Uitdehaag |
| Solution 2 | 0nepeop1e |
