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

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

$em = 'support@pay.creato.live';
$pww = 'Arun@811214';
$server = 'smtp.hostinger.com';

function sendOTPEmail($email, $otp, $sender_email) {
    
    global $em, $pww, $server;
    
    $subject = "Your OTP Code";
    $message = "Your OTP code is: " . $otp . ". It is valid for 5 minutes.";


    // Initialize PHPMailer
    $mail = new PHPMailer(true);

    try {
        // SMTP settings
        $mail->isSMTP();
        $mail->Host       = $server;
        $mail->SMTPAuth   = true;
        $mail->Username   = $em; // Your Hostinger email
        $mail->Password   = $pww; // Your email password
        $mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS;
        $mail->Port       = 465;

        // Email headers
        $mail->setFrom($em, 'PaglaUPI UPI Gateway');
        $mail->addAddress($email, "You");
        $mail->addReplyTo($sender_email, 'Support');

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

        // Send email
        return $mail->send();
    } catch (Exception $e) {
        return "Email could not be sent. Error: " . $mail->ErrorInfo;
    }
}
?>