onQueue($queue); $this->params = $params; } /** * Execute the job. * * @return void */ public function handle() { if (admin_setting('email_host')) { Config::set('mail.host', admin_setting('email_host', env('mail.host'))); Config::set('mail.port', admin_setting('email_port', env('mail.port'))); Config::set('mail.encryption', admin_setting('email_encryption', env('mail.encryption'))); Config::set('mail.username', admin_setting('email_username', env('mail.username'))); Config::set('mail.password', admin_setting('email_password', env('mail.password'))); Config::set('mail.from.address', admin_setting('email_from_address', env('mail.from.address'))); Config::set('mail.from.name', admin_setting('app_name', 'XBoard')); } $params = $this->params; $email = $params['email']; $subject = $params['subject']; $params['template_name'] = 'mail.' . admin_setting('email_template', 'default') . '.' . $params['template_name']; try { Mail::send( $params['template_name'], $params['template_value'], function ($message) use ($email, $subject) { $message->to($email)->subject($subject); } ); } catch (\Exception $e) { $error = $e->getMessage(); } $log = [ 'email' => $params['email'], 'subject' => $params['subject'], 'template_name' => $params['template_name'], 'error' => isset($error) ? $error : NULL ]; MailLog::create($log); $log['config'] = config('mail'); return $log; } }