<?php
// config/mailer.php
// Thin wrapper — uses PHP mail() by default.
// Swap the body of send_mail() for PHPMailer/SMTP if needed.

function send_mail(string $to, string $subject, string $htmlBody): bool {
    $from    = 'no-reply@rsis.com';         // ← change to your domain
    $fromName = 'RSIS Submission System';

    $headers  = "MIME-Version: 1.0\r\n";
    $headers .= "Content-Type: text/html; charset=UTF-8\r\n";
    $headers .= "From: =?UTF-8?B?" . base64_encode($fromName) . "?= <$from>\r\n";
    $headers .= "Reply-To: $from\r\n";
    $headers .= "X-Mailer: PHP/" . phpversion();

    $fullBody = "
    <!DOCTYPE html>
    <html><head><meta charset='UTF-8'></head>
    <body style='font-family:Inter,Arial,sans-serif;background:#f0f2f5;padding:30px'>
      <div style='max-width:520px;margin:auto;background:#fff;border-radius:12px;
                  overflow:hidden;box-shadow:0 4px 20px rgba(0,0,0,.08)'>
        <div style='background:#1a3c5e;padding:24px;text-align:center'>
          <h2 style='color:#fff;margin:0;font-size:1.1rem'>RSIS Submission System</h2>
        </div>
        <div style='padding:28px 28px 24px;color:#374151;line-height:1.6;font-size:.93rem'>
          $htmlBody
        </div>
        <div style='background:#f9fafb;padding:16px;text-align:center;
                    font-size:.78rem;color:#9ca3af;border-top:1px solid #e5e7eb'>
          This is an automated message. Please do not reply directly to this email.
        </div>
      </div>
    </body></html>";

    return mail($to, $subject, $fullBody, $headers);
}