1

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']}}.

Wahyu Kristianto
  • 8,719
  • 6
  • 43
  • 68
smrithi
  • 67
  • 8
  • Does this answer your question? [Log of Laravel Scheduler](https://stackoverflow.com/questions/58627329/log-of-laravel-scheduler) – Wahyu Kristianto Feb 09 '22 at 07:39
  • Does this answer your question? [PHP mail function doesn't complete sending of e-mail](https://stackoverflow.com/questions/24644436/php-mail-function-doesnt-complete-sending-of-e-mail) – Tangentially Perpendicular Feb 09 '22 at 08:00

2 Answers2

0

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

0

have you setup the cron job in crontab? if not nothing would run

read https://laravel.com/docs/8.x/scheduling#running-the-scheduler

0nepeop1e
  • 137
  • 7