data = $data; $this->email_subject = $email_subject; $this->from_email = $from; $this->attachment = $attachment; $this->template = $template; $this->to = $to; } /** * Execute the job. * * @return void */ public function handle() { try{ if(empty($this->to)){ throw new \Exception("Recipient email is missing."); } Mail::to($this->to)->send( new SendEmail( $this->data, $this->email_subject, $this->from_email, $this->attachment, $this->template ) ); $this->result['message'] = 'E-Mail has been send successfully.'; $this->result['status'] = true; @unlink($this->attachment); }catch (\Throwable $ex){ $this->result['message'] = $ex->getMessage(); $this->result['status'] = false; } $this->logData['SEND_EMAIL'] = $this->prepareLogData(); appLog($this->logData); } private function prepareLogData(){ return [ 'sending_info' => [ 'from' => $this->from_email, 'to' => $this->to, 'subject' => $this->email_subject ], 'response' => $this->result ]; } }