emailer update fixed so it can now send to multiple recipients

This commit is contained in:
Simon Pocrnjič
2025-10-15 23:46:44 +02:00
parent ddfc79ffe8
commit ed62311ba4
7 changed files with 172 additions and 28 deletions
+7
View File
@@ -12,6 +12,7 @@
use App\Models\EmailLog;
use App\Models\EmailLogStatus;
use App\Models\EmailTemplate;
use App\Models\MailProfile;
class AutoMailDispatcher
{
@@ -95,6 +96,8 @@ public function maybeQueue(Activity $activity, bool $sendFlag = true): array
$log->fill([
'uuid' => (string) \Str::uuid(),
'template_id' => $template->id,
'mail_profile_id' => optional(MailProfile::query()->where('active', true)->orderBy('priority')->orderBy('id')->first())->id,
'user_id' => auth()->id(),
'to_email' => (string) ($recipients[0] ?? ''),
'to_recipients' => $recipients,
'subject' => (string) ($rendered['subject'] ?? $template->subject_template ?? ''),
@@ -107,6 +110,10 @@ public function maybeQueue(Activity $activity, bool $sendFlag = true): array
'client_case_id' => $clientCase?->id,
'contract_id' => $contract?->id,
]);
// If multiple recipients, keep to_email null to avoid implying a single primary recipient
if (count($recipients) > 1) {
$log->to_email = null;
}
$log->save();
$log->body()->create([