<?php

require __DIR__ . '/../lib/PHPMailer/PHPMailer.php';
require __DIR__ . '/../lib/PHPMailer/SMTP.php';
require __DIR__ . '/../lib/PHPMailer/Exception.php';

use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

function kirimEmail($to, $nama, $subject, $message)
{
    $mail = new PHPMailer(true);

    try {
        // ================= SMTP CONFIG =================
        $mail->isSMTP();
        $mail->Host       = 'mail.hitasumut.org'; // 🔥 biasanya ini
        $mail->SMTPAuth   = true;
        $mail->Username   = 'chairman@hitasumut.org';
        $mail->Password   = 'hitasumut2026';
        $mail->SMTPSecure = 'ssl';
        $mail->Port       = 465;

        // ================= EMAIL =================
        $mail->setFrom('treasure@hitasumut.org', 'HITA SUMUT');
        $mail->addAddress($to, $nama);

        $mail->isHTML(true);
        $mail->Subject = $subject;
        $mail->Body    = $message;

        $mail->send();

        return true;

    } catch (Exception $e) {
        return false;
    }
}