user(); $company = $user->company(); $smtp_host = $request->input('smtp_host', $company->smtp_host); $smtp_port = $request->input('smtp_port', $company->smtp_port); $smtp_username = $request->input('smtp_username', $company->smtp_username); $smtp_password = $request->input('smtp_password', $company->smtp_password); $smtp_encryption = $request->input('smtp_encryption', $company->smtp_encryption ?? 'tls'); $smtp_local_domain = $request->input('smtp_local_domain', strlen($company->smtp_local_domain) > 2 ? $company->smtp_local_domain : null); $smtp_verify_peer = $request->input('verify_peer', $company->smtp_verify_peer ?? true); config([ 'mail.mailers.smtp' => [ 'transport' => 'smtp', 'host' => $smtp_host, 'port' => $smtp_port, 'username' => $smtp_username, 'password' => $smtp_password, 'encryption' => $smtp_encryption, 'local_domain' => $smtp_local_domain, 'verify_peer' => $smtp_verify_peer, 'timeout' => 5, ], ]); (new \Illuminate\Mail\MailServiceProvider(app()))->register(); try { Mail::mailer('smtp')->to($user->email, $user->present()->name())->send(new TestMailServer('Email Server Works!', strlen($company->settings->custom_sending_email) > 1 ? $company->settings->custom_sending_email : $user->email)); } catch (\Exception $e) { app('mail.manager')->forgetMailers(); return response()->json(['message' => $e->getMessage()], 400); } app('mail.manager')->forgetMailers(); return response()->json(['message' => 'Ok'], 200); } }