PHPMailer not working in infinityfree but works on localhost

PHPMailer doesn’t work on infinityfree but works in localhost using XAMPP

here it is the error:

Invalid address: (to):
Message could not be sent.Mailer Error: You must provide at least one recipient email address.

This is my code:

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

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


    $data = JSON_DECODE(file_get_contents('php://input'));
    $emailToName = $data->name;
    $emailTo = $data->email;
    $body = $data->body;

    $emailFrom = "[email protected]";
    $emailFromName = "MyName";

    $mail = new PHPMailer;
    $mail->isSMTP(); 
    $mail->SMTPDebug = 2; 
    $mail->Host = "smtp.gmail.com"; 
    $mail->Port = 587;
    $mail->SMTPSecure = 'tls';
    $mail->SMTPAuth = true;
    $mail->Username = "[email protected]";
    $mail->Password = "xxxxxxxxx";
    $mail->setFrom($emailFrom, $emailFromName);
    $mail->addAddress($emailTo, $emailToName);
    $mail->Subject = 'Test Email';
    $mail->msgHTML("Test Email");

    
    if(!$mail->send()){
        echo 'Message could not be sent.';
        echo 'Mailer Error: ' . $mail->ErrorInfo;
    }else{
        $mailToMe->send();
        $data = json_encode(["alert" => "Message sent!"]);

        echo $data;
    }

The passing of data from file_get_contents is successful but it is not working. But in my localhost it is working. I use Gmail and I’m only sending gmail emails.