-1

I've got a strange problem: the same script is working in a different site I've built but not on my current one. The php script refers to a html page (a submitting form) and I just want to send it to an email. Here's the HTML code:

<form class="form-horizontal" action="invio_mail.php">

    <div class="form-group">
        <label for="indirizzo">Indirizzo attivazione</label>
        <input id="indirizzo" name="indirizzo" type="text" class="form-control" placeholder="Via Roma, 15" required autofocus>
    </div>

    <div class="form-group">
        <label for="modem">Tipo di modem</label>
            <select id="modem" name="modem" class="form-control">
            <option>Indoor</option>
            <option>Outdoor</option>
            </select>
    </div>
    ....
<input name="submit" class="btn btn-lg btn-primary btn-block" type="submit" value="Invia">

And here's the script:

    <?php
$mailto = 'myemail@gmail.com'; 
$subject = 'Form';

$error_message = 'Wooops! Something goes wrong.';
$success_message = '<strong><em>SENT!</em></strong>';

$indirizzo = $_POST['indirizzo']; 
$modem = $_POST['modem'];
$consegna = $_POST['consegna'];
$nome = $_POST['nome'];
$cognome = $_POST['cognome'];
$dob = $_POST['dob'];
$paese = $_POST['paese'];
$citta = $_POST['citta'];
$codice_fiscale = $_POST['codice_fiscale'];
$cellulare = $_POST['cellulare'];
$documento = $_POST['documento'];
$scadenza_doc = $_POST['scadenza_doc'];
$rilascio_doc = $_POST['rilascio_doc'];
$email = $_POST['email'];
$note = $_POST['note'];

$message = "The following variables has been registered: $indirizzo $modem $consegna $nome $cognome $dob $paese $citta $codice_fiscale $cellulare $documento $scadenza_doc $rilascio_doc $email $note"; 
$headers = "Da: " . "X-Mailer: PHP/" . phpversion(); 

if (mail($mailto, $subject, $message, $headers)) {
    echo("<br>$success_message <br><br><br>");

;
} else {
    echo($error_message);
}
?>

I receive the mail but it won't me display my variables! I don't know why and i'm getting crazy. The message is only "The following variables has been registered" followed by nothing at all..am I missing something in the syntax? In my old site is working fine.

Thank you all for your patience.

ADyson
  • 57,178
  • 14
  • 51
  • 63
Federico
  • 5
  • 1

1 Answers1

0

CodeCaster's comment is right, your form is making a request via the HTTP GET method - this is the default if you don't specify a method attribute on your form. But your PHP expects to find the variables in the $_POST array, which is only populated if the request is made using the HTTP POST method.

The solution is very simple - tell your form what method to use:

<form class="form-horizontal" action="invio_mail.php" method="POST">
ADyson
  • 57,178
  • 14
  • 51
  • 63
  • Yep, he was right. Thank you so much. I hope I can give something back to this community, someday! – Federico May 02 '18 at 15:16
  • @Federico no problem. You can give back, right now, by marking the answer as "accepted" (click the green tick next to the question so it goes green, see https://meta.stackexchange.com/a/5235) - thanks :-) – ADyson May 02 '18 at 15:17