Files
coolify/app/Notifications/Channels/TransactionalEmailChannel.php
Andras Bacsai 16c0cd10d8 rector: arrrrr
2025-01-07 14:52:08 +01:00

43 lines
1.1 KiB
PHP

<?php
namespace App\Notifications\Channels;
use App\Models\User;
use Exception;
use Illuminate\Mail\Message;
use Illuminate\Notifications\Notification;
use Illuminate\Support\Facades\Mail;
class TransactionalEmailChannel
{
public function send(User $user, Notification $notification): void
{
$settings = instanceSettings();
if (! data_get($settings, 'smtp_enabled') && ! data_get($settings, 'resend_enabled')) {
return;
}
$email = $user->email;
if (! $email) {
return;
}
$this->bootConfigs();
$mailMessage = $notification->toMail($user);
Mail::send(
[],
[],
fn (Message $message) => $message
->to($email)
->subject($mailMessage->subject)
->html((string) $mailMessage->render())
);
}
private function bootConfigs(): void
{
$type = set_transanctional_email_settings();
if (! $type) {
throw new Exception('No email settings found.');
}
}
}