How to send email with schedule queue in laravel?

Member

by adan , in category: PHP Frameworks , 9 months ago

How to send email with schedule queue in laravel?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by tressie.damore , 9 months ago

@adan 

To send an email with a scheduled queue in Laravel, follow these steps:

  1. Create a new Mailable class by running the following command:
1
php artisan make:mail NewEmail


  1. Edit the NewEmail class to define the email template and data to be passed to the view.
  2. Create a new job class by running the following command:
1
php artisan make:job SendScheduledEmail


  1. Edit the SendScheduledEmail class to send the email using the Mailable class created in step 2.
  2. Use the Queue facade to dispatch the job with a delay. For example, to send the email in 1 hour, use the following code:
1
Mail::to($email)->queue((new NewEmail())->delay(now()->addHour()));


  1. Update your .env file to point to a queue driver that supports delayed jobs, such as redis or database.
  2. Start your queue worker by running the following command:
1
php artisan queue:work


Your email will now be sent with a scheduled queue in Laravel.

Related Threads:

How to send emails in queue in laravel?
How to send email in laravel?
How to send an email with laravel?
How to send html format through email in laravel?
How to call command schedule via url on the laravel?
How to put schedule task jobs in chain in laravel?