from = $from; $this->user = $user; $this->mailbox = $mailbox; } /** * Execute the job. * * @return void */ public function handle() { // Configure mail driver according to Mailbox settings \App\Misc\Mail::setMailDriver($this->mailbox); $exception = null; try { Mail::to([['name' => '', 'email' => $this->from]]) ->send(new UserEmailReplyError()); } catch (\Exception $e) { // We come here in case SMTP server unavailable for example activity() ->withProperties([ 'error' => $e->getMessage().'; File: '.$e->getFile().' ('.$e->getLine().')', ]) ->useLog(\App\ActivityLog::NAME_EMAILS_SENDING) ->log(\App\ActivityLog::DESCRIPTION_EMAILS_SENDING_WRONG_EMAIL); $exception = $e; } $status_message = ''; if ($exception) { $status = SendLog::STATUS_SEND_ERROR; $status_message = $exception->getMessage(); } else { $failures = Mail::failures(); // Save to send log if (!empty($failures)) { $status = SendLog::STATUS_SEND_ERROR; } else { $status = SendLog::STATUS_ACCEPTED; } } SendLog::log(null, null, $this->from, SendLog::MAIL_TYPE_WRONG_USER_EMAIL_MESSAGE, $status, null, $this->user->id, $status_message); if ($exception) { throw $exception; } } }