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();
|
2023-07-27 19:26:15 +00:00
|
|
|
if (data_get($settings, 'smtp_enabled') !== true) {
|
2023-06-13 08:51:58 +00:00
|
|
|
return;
|
|
|
|
}
|
2023-06-12 10:00:01 +00:00
|
|
|
$email = $notifiable->email;
|
|
|
|
if (!$email) {
|
|
|
|
return;
|
|
|
|
}
|
2023-06-20 17:08:43 +00:00
|
|
|
$this->bootConfigs();
|
2023-06-12 10:00:01 +00:00
|
|
|
$mailMessage = $notification->toMail($notifiable);
|
|
|
|
Mail::send(
|
|
|
|
[],
|
|
|
|
[],
|
2023-08-08 09:51:36 +00:00
|
|
|
fn(Message $message) => $message
|
2023-06-12 10:00:01 +00:00
|
|
|
->from(
|
2023-07-27 19:26:15 +00:00
|
|
|
data_get($settings, 'smtp_from_address'),
|
|
|
|
data_get($settings, 'smtp_from_name')
|
2023-06-12 10:00:01 +00:00
|
|
|
)
|
|
|
|
->to($email)
|
|
|
|
->subject($mailMessage->subject)
|
|
|
|
->html((string)$mailMessage->render())
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-06-20 17:08:43 +00:00
|
|
|
private function bootConfigs(): void
|
2023-06-12 10:00:01 +00:00
|
|
|
{
|
2023-06-12 14:39:48 +00:00
|
|
|
set_transanctional_email_settings();
|
2023-06-12 10:00:01 +00:00
|
|
|
}
|
2023-08-08 09:51:36 +00:00
|
|
|
}
|