0

I have a laravel project, I need to send email to the author of a ticket when a response is added. I've added mailtrap configuration in .env, ran the command php artisan make:mail NotificationEmail. I want the email to be sent in the background without redirecting to a new page.

In my controller

use App\Mail\NotificationEmail;
use Illuminate\Support\Facades\Mail;

$user=User::where('id',$ticket->user_id)->first();
            $details = [
                'user_id' => $request->user_id,
                'message' => $request->message,
            ];

        Mail::to($user->email)->send(new NotificationEmail($details));  

In NotificationEmail.php

<?php

namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;

class NotificationEmail extends Mailable
{
    use Queueable, SerializesModels;

    public $details;
    /**
     * Create a new message instance.
     *
     * @return void
     */
    public function __construct($details)
    {
        $this->details = $details;
    }

    /**
     * Build the message.
     *
     * @return $this
     */
    public function build()
    {
        return $this->from('mail@example.com', 'Mailtrap');
    }
}
desktreTJ
  • 1
  • 1

1 Answers1

0

Please provide enough informations to help this. how ever you can use laravel jobs to send email with background process

https://laravel.com/docs/9.x/queues