2023-06-12 10:00:01 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Notifications\Channels;
|
|
|
|
|
|
|
|
|
|
use App\Models\User;
|
2023-08-31 13:00:59 +00:00
|
|
|
use Exception;
|
2023-06-12 10:00:01 +00:00
|
|
|
use Illuminate\Mail\Message;
|
|
|
|
|
use Illuminate\Notifications\Notification;
|
|
|
|
|
use Illuminate\Support\Facades\Mail;
|
|
|
|
|
|
|
|
|
|
class TransactionalEmailChannel
|
|
|
|
|
{
|
2025-01-07 14:31:43 +00:00
|
|
|
public function send(User $notifiable, Notification $notification): void
|
2023-06-12 10:00:01 +00:00
|
|
|
{
|
2024-10-01 08:37:40 +00:00
|
|
|
$settings = instanceSettings();
|
2024-06-10 20:43:34 +00:00
|
|
|
if (! data_get($settings, 'smtp_enabled') && ! data_get($settings, 'resend_enabled')) {
|
2023-06-13 08:51:58 +00:00
|
|
|
return;
|
|
|
|
|
}
|
2025-08-18 12:54:08 +00:00
|
|
|
|
|
|
|
|
// Check if notification has a custom recipient (for email changes)
|
|
|
|
|
$email = property_exists($notification, 'newEmail') && $notification->newEmail
|
|
|
|
|
? $notification->newEmail
|
|
|
|
|
: $notifiable->email;
|
|
|
|
|
|
2024-06-10 20:43:34 +00:00
|
|
|
if (! $email) {
|
2023-06-12 10:00:01 +00:00
|
|
|
return;
|
|
|
|
|
}
|
2023-06-20 17:08:43 +00:00
|
|
|
$this->bootConfigs();
|
2025-01-07 14:31:43 +00:00
|
|
|
$mailMessage = $notification->toMail($notifiable);
|
2023-09-01 13:52:18 +00:00
|
|
|
Mail::send(
|
|
|
|
|
[],
|
|
|
|
|
[],
|
|
|
|
|
fn (Message $message) => $message
|
|
|
|
|
->to($email)
|
|
|
|
|
->subject($mailMessage->subject)
|
2024-06-10 20:43:34 +00:00
|
|
|
->html((string) $mailMessage->render())
|
2023-09-01 13:52:18 +00:00
|
|
|
);
|
2023-06-12 10:00:01 +00:00
|
|
|
}
|
|
|
|
|
|
2023-06-20 17:08:43 +00:00
|
|
|
private function bootConfigs(): void
|
2023-06-12 10:00:01 +00:00
|
|
|
{
|
2023-08-31 13:00:59 +00:00
|
|
|
$type = set_transanctional_email_settings();
|
2025-02-27 11:56:37 +00:00
|
|
|
if (blank($type)) {
|
2023-08-31 13:00:59 +00:00
|
|
|
throw new Exception('No email settings found.');
|
|
|
|
|
}
|
2023-06-12 10:00:01 +00:00
|
|
|
}
|
2023-08-08 09:51:36 +00:00
|
|
|
}
|