format('Y-m-d H:i:s'));
$cta = '';
$url = isset($templateValue['url']) ? (string) $templateValue['url'] : '';
if (filter_var($url, FILTER_VALIDATE_URL)) {
$safeUrl = self::escapeHtml($url);
$cta = 'Open Link';
}
return '
' . $title . '
' . $content . '
' . $cta . '
Sender: ' . $brand . '
Sent at: ' . $sendTime . '
';
}
/**
* Send a pre-rendered HTML email using the available Laravel mail API.
*/
public static function sendHtmlMail(string $email, string $subject, string $html): void
{
$mailer = Mail::getFacadeRoot();
if ($mailer && method_exists($mailer, 'html')) {
Mail::html($html, function ($message) use ($email, $subject) {
$message->to($email)->subject($subject);
});
return;
}
Mail::send([], [], function ($message) use ($email, $subject, $html) {
$message->to($email)->subject($subject);
if (method_exists($message, 'getSymfonyMessage')) {
$symfonyMessage = $message->getSymfonyMessage();
if ($symfonyMessage && method_exists($symfonyMessage, 'html')) {
$symfonyMessage->html($html);
return;
}
}
if (method_exists($message, 'setBody')) {
$message->setBody($html, 'text/html');
return;
}
throw new RuntimeException('Unsupported mail message driver for html body.');
});
}
/**
* Escape text before inserting it into an HTML email template.
*/
private static function escapeHtml(string $text): string
{
return htmlspecialchars($text, ENT_QUOTES, 'UTF-8');
}
}