<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
// Load Composer's autoloader
require 'vendor/autoload.php';
function sendmail($email,$otp)
{
    $mail = new PHPMailer(true);
    try {
        // Server settings
        $mail->SMTPDebug = 1;                      // Enable verbose debug output (set to 2 for detailed logs)
        $mail->isSMTP();                            // Set mailer to use SMTP
        $mail->Host = 'email-smtp.us-west-2.amazonaws.com';     // Specify main and backup SMTP servers
        $mail->SMTPAuth = true;                   // Enable SMTP authentication
        $mail->Username = 'AKIAZZHLWCCQWN3TU5XX'; // SMTP username
        $mail->Password = 'BFcOOzH1rxiafR5oWHsBYMoASSKVsdy6lP7iM9lmF31m';        // SMTP password
        $mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; // Enable TLS encryption, `PHPMailer::ENCRYPTION_SMTPS` also accepted
        $mail->Port = 587;                    // TCP port to connect to

        // Recipients
        $mail->setFrom('noreply@support.teamarcs.com', 'Standpoint Rewards');
        $mail->addAddress($email); // Add a recipient
        //$mail->addReplyTo('your_email@example.com', 'Information');

        // Content
        $mail->isHTML(true);                        // Set email format to HTML
        $mail->Subject = $otp.' - OTP for verification - StandPoint Rewards';
        //$emailMessage = "<table><tr><td style='padding-bottom: 20px;'><span style='font-size:24px;'>OTP Verification Code</span></td></tr><tr><td>Hi there,</td></tr><tr><td style='padding-bottom: 20px;'>Please enter the below code to complete verification:</td></tr><tr><td><span style='font-size:24px;'>".$otp."</span></td></tr><tr><td style='padding-top:10px;'>Please do not share this code with anyone.</td></tr><tr><td style='padding-top:30px;'>Best regards,</td></tr><tr><td><b>StandPoint Rewards</b></td></tr></table>";
        $emailMessage = "<table><tr><td>Hi there,</td></tr><tr><td style='padding-bottom: 20px;'>Please enter the below code to complete verification:</td></tr><tr><td><span style='font-size:24px;'>".$otp."</span></td></tr><tr><td style='padding-top:10px;'>Please do not share this code with anyone.</td></tr><tr><td style='padding-top:30px;'>Best regards,</td></tr><tr><td><b>StandPoint Rewards</b></td></tr></table>";
        //echo $emailMessage;
        $mail->MsgHTML($emailMessage);
        // $mail->SMTPOptions = [
        //   'ssl' => [
        //     'verify_peer' => false,
        //     'verify_peer_name' => false,
        //     'allow_self_signed' => true,
        //   ],
        // ];
        $mail->send();
        return true;
    } catch (Exception $e) {
        return false;
    }
}