first(); $setting = Setting::where('key', 'setting')->first(); if (!$mail || !$setting) { return null; } $mail = json_decode($mail->value); $company = json_decode($setting->value)->company ?? 'Your Company'; $password = ''; if (isset($mail->password)) { $decrypted = (new SignRSA())->DecryptFunc($mail->password); $password = $decrypted ?: $mail->password; } $transport = $mail->transport ?? 'smtp'; $encryption = $mail->encryption ?? config('mail.mailers.smtp.encryption'); if ($encryption === 0 || $encryption === '0' || $encryption === 'starttls') { $encryption = 'tls'; } $config = config('mail'); $config['default'] = $transport; $config['from'] = [ 'address' => $mail->from_address ?? $mail->user ?? config('mail.from.address', 'no-reply@example.com'), 'name' => $mail->from_name ?? $company, ]; $config['mailers'][$transport] = array_merge($config['mailers'][$transport] ?? [], [ 'transport' => $transport, 'host' => $mail->host ?? '', 'port' => $mail->port ?? 587, 'encryption' => $encryption, 'username' => $mail->user ?? '', 'password' => $password, ]); return $config; }); if ($config) { self::$resolved = $config; Config::set('mail', $config); } } }