How do I get the contact form to work with phpmailer?

I need your help: my site has a form where the user can contact the company and, before the site was online, I edited php.ini and sendmail.ini (xampp’s file) and everything was fine on the localhost. Once the site has been uploaded to aruba hosting, the form has stopped working and reading online I must use phpmailer. Here is the code for the site to do its work on localhost:

<!-- HOMEPAGE -->

<div class="subscription"> <h2 class="registrati"> CONTATTACI</h2> </div>

<!-- container -->

<div class="container-fluid">

<form class="row g-3 justify-content-center" style="margin:0 auto; width:80%;" id="form" action="#">

<div class="col-md-6">

<label for="inputNome" class="form-label" id="labels">Nome</label>

<input type="text" name="nome" class="form-control" id="inputNome" required> </div>

<div class="col-md-6">

<label for="inputCognome" class="form-label" id="labels">Cognome</label>

<input type="text" name="cognome" class="form-control" id="inputCognome"> </div>

<div class="col-md-6">

<label for="inputEmail" class="form-label" id="labels">Indirizzo Email</label>

<input type="email" name="email" class="form-control" id="inputEmail" required> </div> <div class="col-md-6">

<label for="inputTelefono" class="form-label" id="labels">Telefono</label>

<input type="text" name="telefono" class="form-control" id="inputTelefono"> </div> <div class="col-12">

<label for="inputAzienda" class="form-label" id="labels">Azienda</label>

<input type="text" name="azienda" class="form-control" id="inputAzienda" placeholder="Atomic srl" required> </div>

<div class="mb-3">

<label for="exampleFormControlTextarea1" class="form-label" id="labels">Messaggio</label> <textarea class="form-control" name="messaggio" id="exampleFormControlTextarea1" rows="3"></textarea> </div>

<br>

<div class="col-12 buttonarea">

<button type="submit" class="btn btn-outline-dark" name="invia" id="invia">Invia</button> <span></span> </div>

</form>

</div>

and this is the the code I found online to make the form work with phpmailer :


    <?php
    use PHPMailerPHPMailerPHPMailer;
    use PHPMailerPHPMailerSMTP;
    use PHPMailerPHPMailerException;
    
    require 'phpmailer/src/Exception.php';
    require 'phpmailer/src/PHPMailer.php';
    require 'phpmailer/src/SMTP.php';
    
    $mail = new PHPMailer(true); //se true vengono sollevate eventuali eccezioni utili per il debugging
    
    try {
        //Impostazioni server
        $mail->SMTPDebug = SMTP::DEBUG_SERVER;                //Debug mode
        $mail->isSMTP();                                      //Invio tramite SMTP
        $mail->Host       = 'smtp.gmail.com';                 //Server SMTP
        $mail->SMTPAuth   = true;                             //Abilita autenticazione SMTP
        $mail->Username   = '[email protected]';                 //SMTP username
        $mail->Password   = 'lfpamoizwjsdhpfj';                //SMTP password
        $mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;   //Abilita TLS implicito
        $mail->Port       = 587;                              //Porta SMTP
    
        //Recipients
        $mail->setFrom('[email protected]', 'User');
        $mail->addAddress('[email protected]', 'Dest');  //Indirizzo destinatario
        $mail->addReplyTo('[email protected]', 'User');          //Indirizzo di risposta
        $mail->addCC('[email protected]');                         //Campo CC  (Copia Carbone)    
        $mail->addBCC('[email protected]');                       //Campo BCC (Copia Carbone Nascosta)
    
        //Content
        $mail->isHTML(true);                                  //Abilita invio in HTML
        $mail->Subject = 'Oggetto';                           //Oggetto 
        $mail->Body    = 'This is the HTML message body <b>in bold!</b>'; //Corpo email
        $mail->AltBody = 'This is the body in plain text for non-HTML mail clients'; //Testo alternativo
    
        $mail->send();
        echo 'Il messaggio è stato inviato con successo';
    } catch (Exception $e) {
        echo "Il messaggio non è stato inviato. Errore: {$mail->ErrorInfo}";
    }

?>