Files
ladill-events/app/Services/Events/EventEmailService.php
T
isaacclad a7231ab16f
Deploy Ladill Events / deploy (push) Successful in 45s
fix(email): use client/org name as From display, not Ladill product
Customer-facing outbound mail should appear from the business (organizer,
clinic, company, location), not the Ladill product brand.
2026-07-16 12:01:06 +00:00

154 lines
4.4 KiB
PHP

<?php
namespace App\Services\Events;
use App\Support\AccountBranding;
use Illuminate\Support\Facades\View;
class EventEmailService
{
public function __construct(private readonly EventMailer $mailer) {}
public function lastError(): ?string
{
return $this->mailer->lastError();
}
public function sendProgrammeShare(
string $ownerPublicId,
string $to,
string $eventName,
string $programmeUrl,
?string $attendeeName = null,
?string $organizerEmail = null,
?string $organizerName = null,
): bool {
return $this->send(
$ownerPublicId,
$to,
'Programme for '.$eventName,
'mail.notifications.event-programme',
compact('eventName', 'programmeUrl', 'attendeeName'),
$organizerEmail,
$organizerName,
);
}
public function sendJoinLink(
string $ownerPublicId,
string $to,
string $eventName,
string $joinUrl,
?string $attendeeName = null,
?string $organizerEmail = null,
?string $organizerName = null,
): bool {
return $this->send(
$ownerPublicId,
$to,
'Join '.$eventName,
'mail.notifications.event-join',
compact('eventName', 'joinUrl', 'attendeeName'),
$organizerEmail,
$organizerName,
);
}
public function sendJoinAndProgramme(
string $ownerPublicId,
string $to,
string $eventName,
string $joinUrl,
string $programmeUrl,
?string $attendeeName = null,
?string $organizerEmail = null,
?string $organizerName = null,
): bool {
return $this->send(
$ownerPublicId,
$to,
$eventName.' — programme & join link',
'mail.notifications.event-join-programme',
compact('eventName', 'joinUrl', 'programmeUrl', 'attendeeName'),
$organizerEmail,
$organizerName,
);
}
public function sendRegistrationConfirmation(
string $ownerPublicId,
string $to,
string $eventName,
string $badgeCode,
?string $joinUrl = null,
?string $attendeeName = null,
?string $organizerEmail = null,
?string $organizerName = null,
): bool {
return $this->send(
$ownerPublicId,
$to,
'Registration confirmed — '.$eventName,
'mail.notifications.event-registration-confirmed',
compact('eventName', 'badgeCode', 'joinUrl', 'attendeeName'),
$organizerEmail,
$organizerName,
);
}
public function sendSpeakerInvite(
string $ownerPublicId,
string $to,
string $eventName,
string $portalUrl,
?string $speakerName = null,
?string $organizerEmail = null,
?string $organizerName = null,
): bool {
return $this->send(
$ownerPublicId,
$to,
'Speaker invitation — '.$eventName,
'mail.notifications.event-speaker-invite',
[
'eventName' => $eventName,
'portalUrl' => $portalUrl,
'speakerName' => $speakerName,
],
$organizerEmail,
$organizerName,
);
}
/** @param array<string, mixed> $viewData */
private function send(
string $ownerPublicId,
string $to,
string $subject,
string $view,
array $viewData,
?string $replyToEmail = null,
?string $replyToName = null,
): bool {
$brandingSettings = AccountBranding::forOwnerRef($ownerPublicId);
$viewData['logoUrl'] = AccountBranding::emailLogoUrl($brandingSettings);
$viewData['companyName'] = AccountBranding::companyName($brandingSettings);
// From display: organizer name, else account/company branding — never "Ladill Events".
$fromName = trim((string) ($replyToName ?: $viewData['companyName'] ?? '')) ?: null;
$html = View::make($view, $viewData)->render();
$text = strip_tags(str_replace(['<br>', '<br/>', '<br />'], "\n", $html));
return $this->mailer->send(
$ownerPublicId,
$to,
$subject,
$html,
$text,
$replyToEmail,
$replyToName,
$fromName,
);
}
}