0

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 PHPMailer\PHPMailer\PHPMailer;
    use PHPMailer\PHPMailer\SMTP;
    use PHPMailer\PHPMailer\Exception;
    
    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   = 'silviabiallo@gmail.com';                 //SMTP username
        $mail->Password   = 'lfpamoizwjsdhpfj';                //SMTP password
        $mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;   //Abilita TLS implicito
        $mail->Port       = 587;                              //Porta SMTP
    
        //Recipients
        $mail->setFrom('user@gmail.com', 'User');
        $mail->addAddress('destinatario@gmail.com', 'Dest');  //Indirizzo destinatario
        $mail->addReplyTo('user@gmail.com', 'User');          //Indirizzo di risposta
        $mail->addCC('cc@gmail.com');                         //Campo CC  (Copia Carbone)    
        $mail->addBCC('bcc@gmail.com');                       //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}";
    }

?>
Silvia
  • 13
  • 3
  • 1
    "stopped working" isn't an error message or a useful problem statement. What exact behaviour are you seeing? Are there any error messages? What debugging have you done? See also [ask] and how to make a [mre] of your issue (because the second snippet appears to be something entirely generic, and has not been adapted to work with your form). If you're having difficulty with phpmailer sending emails then you need to follow the guidance at https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting. if you're having trouble with gmail accounts, ensure you've set an App Password in gmail. – ADyson May 10 '23 at 09:49
  • If you force `SMTPDebug` to 2 you should see errors. – Juan May 10 '23 at 10:27

0 Answers0