bootstrap表单提交到电子邮件地址显示错误。标签内的php代码显示在HTML浏览器屏幕上。表单验证无效。
<? php
if($_POST['submit']){
if(!$_POST["name"]){
$error="Please enter your name.";
}
if(!$_POST["phone"]){
$error.="<br/>Please enter your phone no.";
}
if(!$_POST["address"]){
$error.="<br/>Please enter your address.";
}
if(!$_POST["pin"]){
$error.="<br/>Please enter your Pincode.";
}
if(!$_POST["date"]){
$error.="<br/>Please enter the Date.";
}
if(!$_POST["time"]){
$error.="<br/>Please enter the time.";
}
if($error){
$result='<div class="alert alert-danger">'.$error.'</div>'
}
else{
$done="Thank you! RHINOaid will contact you shortly.";
$result='<div class="alert alert-success">'.$done.'</div>';
mail("rhinoaid@gmail.com", "Service Needed",
Name:$_POST["name"]
Phone no:$_POST["phone"]
Address:$_POST["address"]
Pincode:$_POST["pin"]
Date:$_POST["date"]
Time:$_POST["time"]
)
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Form</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<form method="post">
<? php echo $result; ?>
<div class="form-group">
<label for="name">Name:</label>
<input type="text" class="form-control" id="name" placeholder="Enter Name" name="name">
</div>
<div class="form-group">
<label for="Phone">Phone:</label>
<input type="number" class="form-control" id="phone" placeholder="Enter Phone no." name="phone">
</div>
<div class="form-group">
<label for="address">Address:</label>
<input type="text" class="form-control" id="address" placeholder="Enter Address/Venue" name="address">
</div>
<div class="form-group">
<label for="pin">Pincode:</label>
<input type="number" class="form-control" id="pin" placeholder="Enter Pincode" name="pin">
</div>
<div class="form-group">
<label for="date">Date:</label>
<input type="date" class="form-control" id="date" placeholder="dd/mm/yy" name="date">
</div>
<div class="radio">
<label><input type="radio" name="time" value="From 9am to 12pm">From 9am to 12pm</label>
</div>
<div class="radio">
<label><input type="radio" name="time" value="From 12pm to 5pm">From 12pm to 5pm</label>
</div>
<div class="radio">
<label><input type="radio" name="time" value="From 5pm to 9pm">From 5pm to 9pm</label>
</div>
<input type="submit" name="submit" class="btn btn-success btn-sm" value="submit">
</form>
</div>
</body>
</html>
答案 0 :(得分:0)
像这段代码一样,启动php不要空间
<?php
if($_POST['submit']){
if(!$_POST["name"]){
$error="Please enter your name.";
}
if(!$_POST["phone"]){
$error.="<br/>Please enter your phone no.";
}
if(!$_POST["address"]){
$error.="<br/>Please enter your address.";
}
if(!$_POST["pin"]){
$error.="<br/>Please enter your Pincode.";
}
if(!$_POST["date"]){
$error.="<br/>Please enter the Date.";
}
if(!$_POST["time"]){
$error.="<br/>Please enter the time.";
}
if($error){
$result='<div class="alert alert-danger">'.$error.'</div>'
}
else{
$done="Thank you! RHINOaid will contact you shortly.";
$result='<div class="alert alert-success">'.$done.'</div>';
mail("rhinoaid@gmail.com", "Service Needed",
Name:$_POST["name"]
Phone no:$_POST["phone"]
Address:$_POST["address"]
Pincode:$_POST["pin"]
Date:$_POST["date"]
Time:$_POST["time"]
)
}
}
?>