$page, 'store' => app(StoreDetailsService::class)->current(), ]); } public function send(string $locale, ContactRequest $request): RedirectResponse { $key = 'contact:'.$request->ip(); if (RateLimiter::tooManyAttempts($key, self::SEND_LIMIT)) { return back()->withInput()->with('contact_error', __('storefront.contact.too_many')); } RateLimiter::hit($key, self::SEND_DECAY_SECONDS); $data = $request->validated(); $to = app(StoreDetailsService::class)->current()->contact_email; try { if (blank($to)) { throw new \RuntimeException('Store Details has no contact email.'); } Mail::to($to)->send(new ContactMessageMail( $data['name'], $data['email'], $data['message'], $locale, )); } catch (Throwable $e) { Log::error('Contact form: store email failed', ['exception' => $e]); return back()->withInput()->with('contact_error', __('storefront.contact.send_failed')); } // The store already has the message, so a failed confirmation is only logged. try { Mail::to($data['email'])->locale($locale)->send(new ContactConfirmationMail); } catch (Throwable $e) { Log::warning('Contact form: confirmation email failed', ['exception' => $e]); } return redirect()->route('contact')->with('status', __('storefront.contact.sent')); } }