@adan
To send an email with a scheduled queue in Laravel, follow these steps:
- Create a new Mailable class by running the following command:
1
|
php artisan make:mail NewEmail
|
- Edit the NewEmail class to define the email template and data to be passed to the view.
- Create a new job class by running the following command:
1
|
php artisan make:job SendScheduledEmail
|
- Edit the SendScheduledEmail class to send the email using the Mailable class created in step 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()));
|
- Update your .env file to point to a queue driver that supports delayed jobs, such as redis or database.
- Start your queue worker by running the following command:
Your email will now be sent with a scheduled queue in Laravel.