I try to send mail on the background but it's not working.
I run php artisan queue:listen database on the terminal and hit the controller.
on my terminal shows queue in the process but mail not received.
please share the suggestion where i do mistake on my code.
.env file
BROADCAST_DRIVER=log
CACHE_DRIVER=file
SESSION_DRIVER=file
SESSION_LIFETIME=120
QUEUE_DRIVER=database
Mail File
<?php
namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;
class NewOrderSupplierMail extends Mailable
{
use Queueable, SerializesModels;
/**
* Create a new message instance.
*
* @return void
*/
public function __construct()
{
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
return $this->view('emails.test');
}
}
Job File
<?php
namespace App\Jobs;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Mail;
use Illuminate\Contracts\Mail\Mailer;
use App\Mail\NewOrderSupplierMail;
class SendEmailJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
protected $details;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct($details)
{
$this->details = $details;
}
/**
* Execute the job.
*
* @return void
*/
public function handle(Mailer $mailer)
{
$email = new NewOrderSupplierMail();
Mail::to($this->details['email'])->send($email);
}
}
Controller File
use Mail;
use App\Jobs\SendEmailJob;
$details['email'] = 'sumitsinghnaruka@gmail.com';
dispatch(new SendEmailJob($details));
On Terminal
php artisan queue:listen database
[2018-09-29 11:27:05][14143] Processing: App\Jobs\SendEmailJob
[2018-09-29 11:27:05][14144] Processing: App\Jobs\SendEmailJob
[2018-09-29 11:27:05][14145] Processing: App\Jobs\SendEmailJob
[2018-09-29 11:27:05][14146] Processing: App\Jobs\SendEmailJob
[2018-09-29 11:27:06][14147] Processing: App\Jobs\SendEmailJob
[2018-09-29 11:27:06][14148] Processing: App\Jobs\SendEmailJob
[2018-09-29 11:27:06][14149] Processing: App\Jobs\SendEmailJob
[2018-09-29 11:27:06][14150] Processing: App\Jobs\SendEmailJob
[2018-09-29 11:27:06][14151] Processing: App\Jobs\SendEmailJob
[2018-09-29 11:27:06][14152] Processing: App\Jobs\SendEmailJob
[2018-09-29 11:27:07][14153] Processing: App\Jobs\SendEmailJob
[2018-09-29 11:27:07][14154] Processing: App\Jobs\SendEmailJob
[2018-09-29 11:27:07][14155] Processing: App\Jobs\SendEmailJob
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire