K. André
K. André

Reputation: 3

Contact form php troubles

This is the code i use, when i input information into the form the mail sends incomplete emails like if i add 1 to all fields and email name etc it shows:

From:
Email:
Tale:
Sms:
Data:
Levrandør:
Ekstra informasjon:

So im lacking the information.

 <?php 

   $name = $_POST['f_name'];
   $email = $_POST['email'];
   $tale = $_POST['tale'];
   $sms = $_POST['sms'];
   $data = $_POST['data'];
   $levrandor = $_POST['levrandor'];
   $ekstra = $_POST['ekstra'];
   $formcontent="From: $name \n Email: $email \n Tale: $tale \n Sms: $sms \n Data: $data \n Levrandør: $levrandor \n Ekstra informasjon: $ekstra";
   $recipient = "[email protected]";
   $subject = "Melding fra bruker.";
   $mailheader = "From: $email \r\n";

   mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");

   if(mail){

   header('Location: thanks.html');

   }else{ echo "Email ble ikke sendt";}


    ?>

HTML form:

<div class="form_area text-left">
            <form id="contact-form" action="mail.php" method="post">
                <fieldset>
                    <label>Navn:</label>
                    <input type="text" placeholder="">
                    <label>E-mail: (Må fylles inn)</label>
                    <input type="email" placeholder="" required>
                    <label>Forbruk pr mnd (Må fylles inn):</label>
                    <label>Tale:</label>
                    <input type="text" placeholder="" required>
                    <label>Sms:</label>
                    <input type="text" placeholder="" required>
                    <label>Data:</label>
                    <input type="text" placeholder="" required>
                    <label>Levrandør:</label>
                    <input type="text" placeholder="" required>
                    <label>Ekstra informasjon:</label>
                    <textarea rows="3"></textarea><br>
                    <!--<input type="submit" id="submit_button" class="btn" value="Send">-->
                    <button name="submit" type="submit" id="submit_button">Send</button>
              </fieldset>
            </form>
        </div>

Upvotes: 0

Views: 100

Answers (1)

You need to set the name property on the form fields.

The name property should be the same as the key you use in the $_POST array. Like this for example:

<input type="text" name="f_name" placeholder="">

And in PHP

$name = $_POST['f_name'];

You can read more about the $_POST array here.

Upvotes: 2

Related Questions