lasthourcloud/app/Notifications/Channels/TransactionalEmailChannel.php

45 lines
1.2 KiB
PHP
Raw Normal View History

2023-06-12 10:00:01 +00:00
<?php
namespace App\Notifications\Channels;
use App\Models\InstanceSettings;
use App\Models\User;
use Illuminate\Mail\Message;
use Illuminate\Notifications\Notification;
use Illuminate\Support\Facades\Mail;
class TransactionalEmailChannel
{
public function send(User $notifiable, Notification $notification): void
{
2023-06-13 08:51:58 +00:00
$settings = InstanceSettings::get();
if ($settings->extra_attributes?->get('smtp_active') !== true) {
return;
}
2023-06-12 10:00:01 +00:00
$email = $notifiable->email;
if (!$email) {
return;
}
$this->bootConfigs($settings);
$mailMessage = $notification->toMail($notifiable);
Mail::send(
[],
[],
fn (Message $message) => $message
->from(
$settings->extra_attributes?->get('smtp_from_address'),
$settings->extra_attributes?->get('smtp_from_name')
)
->to($email)
->subject($mailMessage->subject)
->html((string)$mailMessage->render())
);
}
private function bootConfigs(InstanceSettings $settings): void
{
2023-06-12 14:39:48 +00:00
set_transanctional_email_settings();
2023-06-12 10:00:01 +00:00
}
}