$settings['from_address'] ?: ($config['from']['address'] ?? null) ?: 'no-reply@example.com', 'name' => $settings['from_name'], ]; $config['mailers'][$settings['transport']] = array_merge( $config['mailers'][$settings['transport']] ?? [], $settings['mailer'], ); Config::set('mail', $config); } public static function refresh(object $mailer): void { self::apply(); if ($mailer instanceof MailManager) { $mailer->forgetMailers(); } } private static function resolve(): ?array { return Cache::remember(self::cacheKey(), self::TTL_SECONDS, function () { if (!Schema::hasTable('setting')) { return null; } $mail = Setting::where('key', 'smtp')->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 ?? null) ?: 'smtp'; $encryption = $mail->encryption ?? null; if ($encryption === 0 || $encryption === '0' || $encryption === 'starttls') { $encryption = 'tls'; } return [ 'transport' => $transport, 'from_address' => ($mail->from_address ?? null) ?: ($mail->user ?? null), 'from_name' => ($mail->from_name ?? null) ?: $company, 'mailer' => array_filter([ 'transport' => $transport, 'host' => $mail->host ?? '', 'port' => $mail->port ?? 587, 'encryption' => $encryption, 'username' => $mail->user ?? '', 'password' => $password, ], fn ($value) => $value !== null), ]; }); } }