From 3f5bb9cca0338cbc61a34df27cb79ea53cbf0285 Mon Sep 17 00:00:00 2001 From: HafizMMoaz Date: Thu, 16 Jul 2026 20:10:00 +0500 Subject: [PATCH] Do not fail a lead conversion when SMTP is not configured SetConfigEmail() throws when the company has no mail host set. In convertToDeal() both sends sit after the client is created and before the deal is made, so an unconfigured mail server returned a 500 and left the conversion half done: client created, deal never made. Both sends are now guarded and the reason logged. The conversion completes. --- src/Http/Controllers/LeadController.php | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/src/Http/Controllers/LeadController.php b/src/Http/Controllers/LeadController.php index fa66520..4cd002a 100644 --- a/src/Http/Controllers/LeadController.php +++ b/src/Http/Controllers/LeadController.php @@ -840,9 +840,19 @@ public function convertToDeal(ConvertToDealRequest $request, Lead $lead) CreateUser::dispatch($request, $client); if ($enableEmailVerification === 'on') { - // Apply dynamic mail configuration - SetConfigEmail(creatorId()); - $client->sendEmailVerificationNotification(); + try { + // Apply dynamic mail configuration + SetConfigEmail(creatorId()); + $client->sendEmailVerificationNotification(); + } catch (\Throwable $e) { + // SetConfigEmail() throws when the company has no SMTP set up. + // The client already exists and the deal still has to be made, + // so a missing mail server must not fail the conversion. + \Log::warning('Client created but its verification email could not be sent', [ + 'client_id' => $client->id, + 'error' => $e->getMessage(), + ]); + } } } @@ -852,7 +862,14 @@ public function convertToDeal(ConvertToDealRequest $request, Lead $lead) ]; // Send Email to client if they are new created. - EmailTemplate::sendEmailTemplate('New User', [$client->id => $client->email], $cArr); + try { + EmailTemplate::sendEmailTemplate('New User', [$client->id => $client->email], $cArr); + } catch (\Throwable $e) { + \Log::warning('Could not send the new client its welcome email', [ + 'client_id' => $client->id, + 'error' => $e->getMessage(), + ]); + } $stage = DealStage::where('pipeline_id', $lead->pipeline_id)->first(); if (!$stage) {