validate(['name' => 'required|string|max:120', 'email' => 'required|email|max:255', 'company' => 'nullable|string|max:120', 'service' => 'nullable|string|max:100', 'message' => 'required|string|min:10|max:5000', 'website' => 'nullable|max:0']); $enquiry = ContactEnquiry::create($this->only(['name', 'email', 'company', 'service', 'message'])); $this->reset(['name', 'email', 'company', 'service', 'message']); $this->submitted = true; defer(fn () => $this->notifyByEmail($enquiry))->always(); } /** Send a notification and record failures without including enquiry contents. */ private function notifyByEmail(ContactEnquiry $enquiry): void { $recipient = config('mail.contact_recipient'); $context = ['enquiry_id' => $enquiry->getKey()]; if (! is_string($recipient) || ! filter_var($recipient, FILTER_VALIDATE_EMAIL)) { Log::warning('Contact enquiry notification skipped: configure CONTACT_ENQUIRY_TO.', $context); return; } $body = implode("\n", [ "Enquiry #{$enquiry->getKey()}", "Name: {$enquiry->name}", "Email: {$enquiry->email}", 'Company: '.($enquiry->company ?: 'Not specified'), 'Service: '.($enquiry->service ?: 'Not specified'), '', $enquiry->message, ]); try { $sent = Mail::raw($body, function (Message $message) use ($recipient, $enquiry): void { $message->to($recipient) ->replyTo($enquiry->email) ->subject('New ABSDEV contact enquiry'); }); } catch (Throwable $exception) { Log::error('Contact enquiry notification failed.', $context + [ 'exception_type' => $exception::class, ]); return; } if ($sent === null) { Log::warning('Contact enquiry notification was not sent.', $context); } } public function render() { return view('livewire.contact-form'); } }