Files
domnitor/app/Services/Channels/EmailChannel.php

58 lines
1.7 KiB
PHP
Raw Normal View History

2025-10-08 14:23:07 +03:00
<?php
namespace App\Services\Channels;
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
use App\Models\Setting;
use App\Helpers\EmailHelper;
use App\Services\Logger;
2025-10-08 14:23:07 +03:00
class EmailChannel implements NotificationChannelInterface
{
private Logger $logger;
public function __construct()
{
$this->logger = new Logger('email_channel');
}
2025-10-08 14:23:07 +03:00
public function send(array $config, string $message, array $data = []): bool
{
try {
$result = EmailHelper::sendNotificationEmail(
$config['email'],
EmailHelper::getEmailSubject($data),
$message,
$data
);
if (!$result['success']) {
$this->logger->error("Email send failed via EmailChannel", [
'email' => $config['email'],
'subject' => EmailHelper::getEmailSubject($data),
'debug_info' => $result['debug_info'] ?? null,
'error' => $result['error'] ?? null
]);
return false;
}
$this->logger->info("Email sent successfully via EmailChannel", [
'email' => $config['email'],
'subject' => EmailHelper::getEmailSubject($data)
]);
2025-10-08 14:23:07 +03:00
return true;
} catch (\Exception $e) {
$this->logger->error("Email send exception in EmailChannel", [
'email' => $config['email'],
'exception' => $e->getMessage(),
'trace' => $e->getTraceAsString()
]);
2025-10-08 14:23:07 +03:00
return false;
}
}
}