38395-vm/mail/MailService.php
Flatlogic Bot 4a91088287 sadiq
2026-02-13 15:07:39 +00:00

25 lines
1.0 KiB
PHP

<?php
// AFG CARS - Mail Service (Offline Simulation)
// Logs all emails to db/mail_log.txt instead of sending them.
class MailService
{
public static function sendMail($to, string $subject, string $htmlBody, ?string $textBody = null, array $opts = [])
{
$logFile = __DIR__ . '/../db/mail_log.txt';
$timestamp = date('Y-m-d H:i:s');
$toAddr = is_array($to) ? implode(', ', $to) : ($to ?? 'Default Admin');
$logEntry = "[$timestamp] TO: $toAddr | SUBJECT: $subject\n";
$logEntry .= "BODY: " . strip_tags($htmlBody) . "\n";
$logEntry .= "--------------------------------------------------\n";
file_put_contents($logFile, $logEntry, FILE_APPEND);
return [ 'success' => true, 'info' => 'Logged to mail_log.txt' ];
}
public static function sendContactMessage(string $name, string $email, string $message, $to = null, string $subject = 'New contact form')
{
return self::sendMail($to, $subject, "<p>From: $name ($email)</p><p>$message</p>");
}
}