title: Send email in background : Laravel 5.4
body: <p>I am using an inbuilt code in Laravel to send Email Notification. Code is below. I am using smtp to send email</p>
  
  <pre><code>class RegisterNotification extends Notification
  {
      use Queueable;
  
      public function __construct($token)
      {
          $this-&gt;token = $token;
      }
  
      public function via($notifiable)
      {
          return ['mail'];
      }
  
      public function toMail($notifiable)
      {
          return (new MailMessage)
                  -&gt;line('hi');
      }
  
      public function toArray($notifiable)
      {
          return [
              //
          ];
      }
  }
  </code></pre>
  
  <p>Here the problem is, it takes around 5 seconds to complete the process and control does not come back. I am assuming that if it come back and do the email sending work in background...it would save a lot of time. </p>
  
  <p>Is there any inbuilt work to do the same? I meant, control should come back and should say email sent...and then it should do the work in background. </p>
  
  <p><strong>Email Sending code in Controller</strong></p>
  
  <pre><code>class apiRegisterController extends Controller
  {
      public function Register(RegisterRequest $request) {
  
          $RegisterNotification = new RegisterNotification($Token);
          $User-&gt;notify($RegisterNotification);
      }
  }
  </code></pre>
  
  <p><strong>Code for Queue</strong></p>
  
  <p><strong>Controller Code</strong></p>
  
  <pre><code>$job = (new SendForgotPasswordEmail($Data))-&gt;onConnection('database');
  dispatch($job);
  </code></pre>
  
  <p><strong>Job</strong></p>
  
  <pre><code>class SendForgotPasswordEmail implements ShouldQueue
  {
      use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
  
      protected $Data;
  
      public $tries = 5;
  
      public function __construct($Data)
      {
          $this-&gt;Data = $Data;
      }
  
      public function handle()
      {
          $Token = $this-&gt;Data["Token"];
          $User = $this-&gt;Data["User"];
          $RegisterNotification = new RegisterNotification($Token);
          $User-&gt;notify($RegisterNotification);
      }
  }
  </code></pre>