Tuesday, April 11, 2017

Sending Email Using Queue (SMTP-GMAIL) in Laravel 5.3 - Part I

In previous post, we have successfully sent an email using Mail::send with some of it's properties and we sent this email using default way or not using background worker or in another word 'queue'. So Right now, we are going to play queue to the email using smtp-gmail :D. mmmm......... Next please follow below instructions
1. Create table for queue and also failed-table too. Queue table is for saving list of some jobs (emails that will be sent) and failed-table is for saving failed list of our emails. For creating those tables, we can use these commands :
php artisan queue:table
php artisan queue:failed-table
So we have two migration files now :
Next, execute migration command:
php artisan migrate
Aaand now we have two tables in our phpmyadmin :
2. Change QUEUE_DRIVER = sync to database on .env file :

3. Create new job :
php artisan make:job {your-job-file-name}

4. Let's create a new route and controller...
5. Actually, we can do this step in step 3, buuut... mmmm.... yaaah... it's okie to seperate it in another step... :D
So... in this step 5, let's complete our handle method :




6. Run php artisan queue:listen
This command is the starting point for our queue job to be executed by laravel.

1 comment: