resolve(); if ($resolved['transport_configured'] && $this->capabilities->has(Capability::EmailTransportConfigure)) { Config::set('mail.default', 'smtp'); Config::set('mail.mailers.smtp.host', $resolved['host']); Config::set('mail.mailers.smtp.port', $resolved['port']); Config::set('mail.mailers.smtp.username', $resolved['username']); Config::set('mail.mailers.smtp.password', $resolved['password']); Config::set('mail.mailers.smtp.encryption', $resolved['encryption']); } if ($resolved['from_address'] !== null) { Config::set('mail.from.address', $resolved['from_address']); } if ($resolved['from_name'] !== null) { Config::set('mail.from.name', $resolved['from_name']); } } public function flush(): void { Cache::forget(self::CACHE_KEY); } /** * @return array{transport_configured: bool, host: string|null, port: int|null, username: string|null, password: string|null, encryption: string|null, from_address: string|null, from_name: string|null} */ private function resolve(): array { $blank = [ 'transport_configured' => false, 'host' => null, 'port' => null, 'username' => null, 'password' => null, 'encryption' => null, 'from_address' => null, 'from_name' => null, ]; // Through BootSettingsCache, not Cache directly: this runs on every // process boot, including the artisan commands that install the // application, and must survive a database that has no tables yet // (or none at all). See that class for the full story. return BootSettingsCache::rememberForever(self::CACHE_KEY, function () use ($blank): array { if (! Schema::hasTable('mail_provider_settings')) { return $blank; } $settings = MailProviderSettings::current(); $hasHost = $settings->host !== null && $settings->host !== ''; return [ 'transport_configured' => $hasHost, 'host' => $settings->host, 'port' => $settings->port, 'username' => $settings->username, 'password' => $settings->password, 'encryption' => $settings->encryption === 'none' ? null : $settings->encryption, 'from_address' => $settings->from_address, 'from_name' => $settings->from_name, ]; }, $blank); } }