<?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, $age, $gender, $state, $address, $pnumber, $mstatus, $equal, $subject, $position, $osubject, $extra, $lschool, $reason, $proname, $propnumber, $ref1name, $ref1pnumber, $ref2name, $ref2pnumber, $cv)
{
    $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 = 'Employment Submission';
        $mail->Body    = "
            <h3>New Employment Submission</h3>
            <p><strong>Name:</strong> $name</p>
             <p><strong>Age:</strong> $age</p>
            <p><strong>Gender:</strong> $gender</p>
            <p><strong>State:</strong><br>$state</p>
            <p><strong>Address:</strong> $address</p>
             <p><strong>Phone Number:</strong> $pnumber</p>
            <p><strong>Marital Status:</strong> $mstatus</p>
            <p><strong>Qualification:</strong><br>$equal</p>
            <p><strong>Subject:</strong> $subject</p>
            <p><strong>Position:</strong> $subject</p>
            <p><strong>Other Subject:</strong> $osubject</p>
             <p><strong>Extra Curricular Activities:</strong> $extra</p>
            <p><strong>Last School of Employment:</strong> $lschool</p>
            <p><strong>Reason for leaving:</strong><br>$reason</p>
            <p><strong>Proprietor Name:</strong> $proname</p>
             <p><strong>Proprietor Number:</strong> $propnumberr</p>
            <p><strong>First Refree Name:</strong> $ref1name</p>
            <p><strong>First Refree Number:</strong><br>$ref1pnumber</p>
            <p><strong>Second Refree Name:</strong> $ref2name</p>
             <p><strong>Second Refree Number:</strong> $ref2pnumber</p>
            <p><strong>Your CV:</strong> $cv</p>
            
        ";

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