2025-10-08 14:23:07 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Services\Channels;
|
|
|
|
|
|
|
|
|
|
use PHPMailer\PHPMailer\PHPMailer;
|
|
|
|
|
use PHPMailer\PHPMailer\Exception;
|
2025-10-08 18:54:34 +03:00
|
|
|
use App\Models\Setting;
|
2025-10-14 00:27:50 +03:00
|
|
|
use App\Helpers\EmailHelper;
|
|
|
|
|
use App\Services\Logger;
|
2025-10-08 14:23:07 +03:00
|
|
|
|
|
|
|
|
class EmailChannel implements NotificationChannelInterface
|
|
|
|
|
{
|
2025-10-14 00:27:50 +03:00
|
|
|
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 {
|
2025-10-14 00:27:50 +03:00
|
|
|
$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;
|
2025-10-14 00:27:50 +03:00
|
|
|
} 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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|