PHP表单未在POST

时间:2015-06-04 22:11:18

标签: php html5 twitter-bootstrap phpmailer

我有以下html表单,当用户点击提交时,它会触发contactengine.php中的php代码,但是我收到的电子邮件和生成的.txt表单中缺少值。

<!------------------from start------------>
  <form method="POST" action="contactengine.php" class="form-inline" >
      <div class="form-group">

       <label>Full Name*</label><br>
        <input name="full_name" type="text" class="form-control" placeholder="Full Name" id="full_name"   required>
        </div>
        <div class="form-group">
        <label>Telephone *</label><br>
        <input name="contact_tel" type="text" class="form-control"  placeholder="Telephone" id="contact_tel" required>
      </div>
<div class="form-group">
        <label>Email *</label><br>
        <input name="contact_email" type="email" class="form-control"   placeholder="Email Address" id="contact_email" required>
      </div>

      <div class="form-group">
        <label>Subject of Enquiry *</label><br>
      <select name="sub_enquiry" class="form-control"  id="sub_enquiry">
            <option value="Assesments" >Assesments</option><option value="Services" >Services</option>
                <option value="Inpections" >Inpections</option>
                <option value="Other" >Other</option>         
      </select>
      </div><br> <br>   
 <label>Your message *</label><br>
      <textarea name="contact_msg" class="form-control" rows="5" id="contact_msg" required  ></textarea> <br >
      <br >
     <button type="submit" class="btn btn-purple"  ><span class="glyphicon glyphicon-envelope"></span> Submit</button>
    </form>

<!----------------------php form------------------>
<?php
$to = "xxxx@gmail.com";
$Subject = "OFSUK.ORG";
$full_name = $_POST['full_name']; 
$contact_email = $_POST['contact_email']; 
$contact_tel = $_POST['contact_tel'];
$sub_enquiry = $_POST['sub_enquiry'];
$contact_msg = $_POST['contact_msg']; 

// validation
$validationOK=true;
if (!$validationOK) {
  header("location:/error.php");
  exit;
}

// prepare email body text
$Body = "";
$Body .= "\n";
$Body .= "Name: ";
$Body .= $full_name;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $contact_email;
$Body .= "\n";
$Body .= "Telephone: ";
$Body .= $contact_tel;
$Body .= "\n";
$Body .= "Enquiry: ";
$Body .= $sub_enquiry;
$Body .= "\n";
$Body .= "Message: ";
$Body .= $contact_msg;
$Body .= "\n";

// send email 
$success = mail($to, $Subject, $Body);
$email_from = $full_name.'<'.$email_from.'>';

$myfile = fopen("emails.txt", "a") or die("Unable to open file!");
$txt = $Body;
fwrite($myfile, "\n". $txt);
fclose($myfile);

// redirect to success page 
if ($success){
  header("location:/");
}
else{
 header("location:/contact-us.php");
}

?>

这两个存储在两个位置,但工作正常,只是没有得到任何数据。

2 个答案:

答案 0 :(得分:0)

更改<button type="submit" class="btn-purple"/>

<input type="submit" name="sbmt" class="btn-purple"/>

然后验证是否已设置sbmt,如果是,则打印出值

答案 1 :(得分:0)

尝试使用

  

pg_escape_string

像...

pg_escape_string($_POST['full_name']);

...修复数据传递问题。