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

require 'vendor/autoload.php';

function sendVerificationCode($toEmail, $code) {
    $mail = new PHPMailer(true);

    try {
        $mail->isSMTP();
        $mail->Host       = 'smtp.secureserver.net';  // ✅ GoDaddy SMTP server
        $mail->SMTPAuth   = true;
        $mail->Username   = 'marshal@m-emp.com';
        $mail->Password   = 'Silver002@@';
$mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS; // ✅ SSL
        $mail->Port       = 465;

        $mail->setFrom('marshal@m-emp.com', 'Marshal Travel');
        $mail->addAddress($toEmail);

        $mail->isHTML(true);
        $mail->Subject = 'Your Verification Code';
        $mail->Body    = "<p>Your verification code is: <strong>$code</strong></p>";

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