Getting 500 POST Error when trying to send an email

I’ve been getting this error and I don’t know what’s wrong.
This is my .js code:

function save(formulario, tipo, file) {
    var formData = new FormData();
    formData.append("formulario", formulario);
    formData.append("tipo", tipo);
    formData.append("file", file);
    $.ajax({
        data: formData,
        url: 'php/save_form.php',
        type: 'POST',
        crossDomain: true,
        jsonpCallback: 'jpCallback',
        processData: false,//
        contentType: false,//
        dataType: "json",
        success: function (data) {
            if (data == "-1") {
                $(".modal-body>h5").html("ERROR");
            } 
            $(".modal").modal('show');
        },
    });
   
}

And then this is my .php file:

<?php
require 'vendor/autoload.php';
use MailjetResources;

$json = $_REQUEST['formulario'];

$json = json_decode($json);
$Email = $json->mail;
$json =  sendMail($json);

Here is the sendMail function.

function sendMail($json)
{
    
    $mj = new MailjetClient('12163db52d218cd7ea59430b24694a76','8e625a6b7d95d3b37f65b29c82102a4d',true,['version' => 'v3.1']);
    $body = [
        'Messages' => [
            [
            'From' => [
                'Email' => "[email protected]",
                'Name' => "Mailjet Pilot"
            ],
            'To' => [
                [
                    'Email' => "[email protected]",
                    'Name' => "passenger 1"
                ]
            ],
            'Subject' => "Your email flight plan!",
            'TextPart' => "Dear passenger 1, welcome to Mailjet! May the delivery force be with you!",
            'HTMLPart' => "<h3>Dear passenger 1, welcome to <a href="https://www.mailjet.com/">Mailjet</a>!</h3><br />May the delivery force be with you!"
        ]
    ]
    ];

    
    $response = $mj->post(Resources::$Email, ['body' => $body]);
    $response->success() && var_dump($response->getData());
 
    return $response;
}

The error shows when I add the last two lines. If I don’t add them the error won’t appear but it won’t send the email.