payment = $payment; $this->email_builder = $email_builder; $this->contact = $contact; } /** * Execute the job. * * * @return void */ public function handle() { if ($this->contact->email) { Mail::to($this->contact->email, $this->contact->present()->name()) ->send(new TemplateEmail($this->email_builder, $this->contact->user, $this->contact->customer)); if (count(Mail::failures()) > 0) { event(new PaymentWasEmailedAndFailed($this->payment, Mail::failures(), Ninja::eventVars())); return $this->logMailError(Mail::failures()); } //fire any events event(new PaymentWasEmailed($this->payment, $this->payment->company, Ninja::eventVars())); //sleep(5); } } private function logMailError($errors) { SystemLogger::dispatch( $errors, SystemLog::CATEGORY_MAIL, SystemLog::EVENT_MAIL_SEND, SystemLog::TYPE_FAILURE, $this->payment->client ); } }