<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

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

function sendOTP($email, $otp){

    $mail = new PHPMailer(true);

    try {

        $mail->isSMTP();
        $mail->Host = 'smtp.gmail.com';
        $mail->SMTPAuth = true;
        $mail->Username = 'YOUR_EMAIL@gmail.com';
        $mail->Password = 'YOUR_APP_PASSWORD'; // NOT normal password
        $mail->SMTPSecure = 'tls';
        $mail->Port = 587;

        $mail->setFrom('YOUR_EMAIL@gmail.com', 'SecureBank');
        $mail->addAddress($email);

        $mail->Subject = "Your Chase Bank OTP Code";
        $mail->Body = "Your login OTP is: $otp. It expires in 5 minutes.";

        $mail->send();
        return true;

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