联系表格php麻烦

时间:2013-07-24 21:54:23

标签: php contact-form

这是我使用的代码,当我在表单中输入信息时,邮件发送不完整的电子邮件,例如,如果我将1添加到所有字段和电子邮件名称等,则显示:

自:
 电子邮件:
 故事:
 短信:
 数据:
 Levrandør:
 Ekstra informasjon:

所以我缺乏信息。

 <?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 = "post@mobilavtalen.no";
   $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表单:

<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>

1 个答案:

答案 0 :(得分:2)

您需要在表单字段上设置name属性。

name属性应与您在key数组中使用的$_POST相同。像这样举例如:

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

在PHP中

$name = $_POST['f_name'];

您可以详细了解$_POST数组here