PHP查询表不起作用?

时间:2015-11-03 13:08:27

标签: php html css3

我试图创建一个网站,我的PHP和HTML不会工作!当我输入数据时,网站不会将信息发送到我的电子邮箱,在输入表单中,我的验证显示而不是占位符!请帮忙!!!!: - )

我的HTML如下:

<form class="form-horizontal" role="form" method="post" action="index.php">
       <div class="form-group">
    <label for="name" class="col-sm-2 control-label">Name</label>
    <div class="col-sm-10">
        <input type="text" class="form-control" id="name" name="name" placeholder="Preferred Name" value="<?php echo htmlspecialchars($_POST['name']); ?>">
    </div>
</div>
<div class="form-group">
    <label for="email" class="col-sm-2 control-label">Email</label>
    <div class="col-sm-10">
        <input type="email" class="form-control" id="email" name="email" placeholder="example@domain.com" value="<?php echo htmlspecialchars($_POST['email']); ?>">
    </div>
</div>
<div class="form-group">
    <label for="number" class="col-sm-2 control-label">Contact Number</label>
    <div class="col-sm-10">
        <input type="text" class="form-control" id="number" name="number" placeholder="0000000000">
    </div>
</div>
<div class="form-group">
    <label for="message" class="col-sm-2 control-label">Message</label>
    <div class="col-sm-10">
        <textarea class="form-control" rows="4" name="message"><?php echo htmlspecialchars($_POST['message']);?></textarea>
    </div>
</div>
<div class="form-group">
    <div class="col-sm-10 col-sm-offset-2">
        <input id="submit" name="submit" type="submit" value="Send" class="btn btn-primary">
    </div>
</div>
<div class="form-group">
    <div class="col-sm-10 col-sm-offset-2">
        <?php echo $result; ?>    
    </div>
</div>

我的PHP如下:

$Tel = Trim(stripslashes($_POST['Tel'])); 
$Email = Trim(stripslashes($_POST['Email'])); 
$Message = Trim(stripslashes($_POST['Message'])); 

// validation
 $validationOK=true;
 if (!$validationOK) {
  print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
 exit;
 }

// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "Tel: ";
$Body .= $Tel;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "\n";
$Body .= "Message: ";
$Body .= $Message;
$Body .= "\n";

// send email 
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");

// redirect to success page 
 if ($success){
  print "<meta http-equiv=\"refresh\`content=\"0;URL=contactthanks.php\">";
 }
 else{   
 print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
 }
 ?>

1 个答案:

答案 0 :(得分:2)

您尚未关闭表单标记,并且在联系中没有给出粘贴此代码并检查的值,并且在使用html5验证时,它将使用占位符设置验证错误消息,例如请输入+您的占位符

  <form class="form-horizontal" role="form" method="post" action="index.php">
           <div class="form-group">
        <label for="name" class="col-sm-2 control-label">Name</label>
        <div class="col-sm-10">
            <input type="text" class="form-control" id="name" name="name" placeholder="Preferred Name" value="<?php echo @htmlspecialchars($_POST['name']); ?>">
        </div>
    </div>
    <div class="form-group">
        <label for="email" class="col-sm-2 control-label">Email</label>
        <div class="col-sm-10">
            <input type="email" class="form-control" id="email" name="email" placeholder="example@domain.com" value="<?php echo @htmlspecialchars($_POST['email']); ?>">
        </div>
    </div>
    <div class="form-group">
        <label for="number" class="col-sm-2 control-label">Contact Number</label>
        <div class="col-sm-10">
            <input type="text" class="form-control" id="number" name="number" placeholder="0000000000" value="<?php echo @$_POST['your_contact_filed_name'] ?>">
        </div>
    </div>
    <div class="form-group">
        <label for="message" class="col-sm-2 control-label">Message</label>
        <div class="col-sm-10">
            <textarea class="form-control" rows="4" name="message"><?php echo htmlspecialchars(@$_POST['message']);?></textarea>
        </div>
    </div>
    <div class="form-group">
        <div class="col-sm-10 col-sm-offset-2">
            <input id="submit" name="submit" type="submit" value="Send" class="btn btn-primary">
        </div>
    </div>
    <div class="form-group">
        <div class="col-sm-10 col-sm-offset-2">
            <?php echo @$result; ?>    
        </div>
    </div>
    </form>