44 lines
1.2 KiB
PHP
44 lines
1.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Services\Notifications;
|
|
|
|
use App\Models\NotificationSetting;
|
|
use Illuminate\Support\Facades\Mail;
|
|
|
|
class EmailNotifier
|
|
{
|
|
public function sendBatch(NotificationSetting $setting, array $messages): void
|
|
{
|
|
$toEmail = $setting->config['to_email'] ?? null;
|
|
|
|
if (! $toEmail) {
|
|
throw new \RuntimeException('Email to_email address is required.');
|
|
}
|
|
|
|
$combined = implode("\n\n---\n\n", $messages);
|
|
|
|
Mail::raw($combined, function ($mail) use ($toEmail, $setting): void {
|
|
$mail->to($toEmail)
|
|
->subject("🐱 Cathy's App — {$setting->name} Notifications");
|
|
});
|
|
}
|
|
|
|
public function sendTest(NotificationSetting $setting): void
|
|
{
|
|
$toEmail = $setting->config['to_email'] ?? null;
|
|
|
|
if (! $toEmail) {
|
|
throw new \RuntimeException('Email to_email address is required.');
|
|
}
|
|
|
|
Mail::raw(
|
|
"🐱 KOL Manager — Test Notification\n\nYour Email channel is configured correctly! 🎉",
|
|
function ($mail) use ($toEmail): void {
|
|
$mail->to($toEmail)->subject('🐱 KOL Manager — Test Notification');
|
|
}
|
|
);
|
|
}
|
|
}
|