<?php
// Enable error reporting
error_reporting(E_ALL);
ini_set('display_errors', 0);

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

require './PHPMailer/src/Exception.php';
require './PHPMailer/src/PHPMailer.php';
require './PHPMailer/src/SMTP.php';

function send_mail($name, $pnumber, $email, $comment)
{
    $mail = new PHPMailer(true);

    try {
        // SMTP settings for cPanel email using SSL
        $mail->isSMTP();
        $mail->Host = 'mail.adamspring.sch.ng';
        $mail->SMTPAuth = true;
        $mail->Username = 'info@adamspring.sch.ng';
        $mail->Password = '6hm[Q86I$a!]K;Sr';
        $mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS;
        $mail->Port = 465;

        // Sender and recipient
        $mail->setFrom('info@adamspring.sch.ng', 'ADAMSPRING COLLEGE - Contact Form');
        $mail->addAddress('info@adamspring.sch.ng');  // Destination email

        // Email content
        $mail->isHTML(true);
        $mail->Subject = 'New Contact Form Submission';
        $mail->Body    = "
            <h3>New Contact Message</h3>
            <p><strong>Name:</strong> $name</p>
             <p><strong>Phone:</strong> $pnumber</p>
            <p><strong>Email:</strong> $email</p>
            <p><strong>Message:</strong><br>$comment</p>
        ";

        $mail->send();
        return true;
    } catch (Exception $e) {
        error_log("Mailer Error: " . $mail->ErrorInfo);
        return false;
    }
}
?>
