I am trying to send email by using laravel queue job

  laravel

I am using laravel queue job for sending email and i am trying to send email but unfortunately i am getting error please help me how can resolve this ? thanks.

please check error

[email protected]:~/htdocs/project/queuejob$ php artisan queue:work

[2021-02-23 06:45:25][29] Processing: AppJobsSendEmailJob

[2021-02-23 06:45:26][29] Failed: AppJobsSendEmailJob

Emailcontroller

   class EmailController extends Controller
{
    public function sendEmail()
    {
        $emailJob = (new SendEmailJob())->delay(Carbon::now()->addSeconds(3));
        dispatch($emailJob);

        echo 'email sent';
    }
}

app/mail/SendMailTest

class SendEmailTest 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('welcome');
    }
}

app/Jobs/SendEmailJob

  class SendEmailJob implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        Mail::to('[email protected]')->send(new SendEmailTest());
    }
}

Route

Route::get('/sendemail',[EmailController::class,'sendEmail']);

.env

MAIL_MAILER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=465
MAIL_USERNAME=d6d151d01264b4
MAIL_PASSWORD=4c5c45ae453ae3
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS=null
MAIL_FROM_NAME="${APP_NAME}"

Source: Laravel

Leave a Reply