credit = $credit; $this->company = $company; } /** * Execute the job. * * * @return void */ public function handle() { //todo - change runtime config of mail driver if necessary MultiDB::setDb($this->company->db); $this->settings = $this->credit->client->getMergedSettings(); $template_style = $this->credit->client->getSetting('email_style'); $this->setMailDriver(); $this->credit->invitations->each(function ($invitation) use ($template_style) { if ($invitation->contact->send_email && $invitation->contact->email) { $message_array = $this->credit->getEmailData('', $invitation->contact); $message_array['title'] = &$message_array['subject']; $message_array['footer'] = 'Sent to '.$invitation->contact->present()->name(); MailRouter::dispatch(new TemplateEmail($message_array, $template_style, $invitation->contact->user, $invitation->contact->client), $invitation->company, $invitation->contact); //fire any events event(new CreditWasEmailed($this->credit, $this->company, Ninja::eventVars())); } }); } private function logMailError($errors) { SystemLogger::dispatch( $errors, SystemLog::CATEGORY_MAIL, SystemLog::EVENT_MAIL_SEND, SystemLog::TYPE_FAILURE, $this->credit->client ); } }