这一直困扰着我,我已经放弃了试图为自己解决问题,但答案可能非常明显......
我的联系表单工作正常,但我没有收到所有字段的输入。我只收到姓名,电话,电子邮件和消息。我给表单字段一个名称属性,所以我不确定发生了什么。
这是HTML:
<form name="sentMessage" id="contactForm" novalidate>
<div class="row">
<div class="col-md-6">
<div class="form-group">
<input type="name" class="form-control" placeholder="Your Name *" name="name" id="name" required data-validation-required-message="Please enter your name.">
<p class="help-block text-danger"></p>
</div>
<div class="form-group">
<input type="phone" class="form-control" placeholder="Your Phone Number *" name="phone" id="phone" required data-validation-required-message="Please enter your phone number.">
<p class="help-block text-danger"></p>
</div>
<div class="form-group">
<input type="email" class="form-control" placeholder="Your Email *" name="email" id="email" required data-validation-required-message="Please enter your email address.">
<p class="help-block text-danger"></p>
</div>
<div class="form-group">
<input type="text" class="form-control" name="suburb" placeholder="Your Suburb *" id="suburb" required data-validation-required-message="Please enter your address.">
<p class="help-block text-danger"></p>
</div>
<div class="select">
<div class="col-sm-6">
<div class="form-group">
<select class="selectpicker" name="state" id="state" data-width="100%" data-height="100%" title="Choose State *" data-style="btn-primary">
<option>QLD</option>
<option>NSW</option>
</select>
</div>
</div>
</div>
<div class="right-form-column">
<div class="col-sm-6">
<div class="form-group">
<input type="number" class="form-control" placeholder="Post Code *" name="postcode" id="postcode" required data-validation-required-message="Please enter your post code.">
<p class="help-block text-danger"></p>
</div>
</div>
</div>
</div>
<div class="col-md-6">
<div class="select">
<div class="col-xs-6">
<div class="form-group">
<select class="selectpicker" name="product1" id="product1" data-width="100%" data-height="100%" data-live-search="true" title="Choose Product" data-style="btn-primary">
<optgroup label="100 Series">
<option>90mm Grey Standard</option>
</optgroup>
</select>
</div>
</div>
</div>
<div class="right-form-column">
<div class="col-xs-6">
<div class="form-group">
<input type="number" class="form-control" placeholder="Quantity" name="quantity1" id="quantity1">
<p class="help-block text-danger"></p>
</div>
</div>
</div>
<div class="select">
<div class="col-xs-6">
<div class="form-group">
<select class="selectpicker" name="product2" id="product2" data-width="100%" data-height="100%" data-live-search="true" title="Choose Product" data-style="btn-primary">
<optgroup label="100 Series">
<option>90mm Grey Standard</option>
</optgroup>
</select>
</div>
</div>
</div>
<div class="right-form-column">
<div class="col-xs-6">
<div class="form-group">
<input type="number" class="form-control" placeholder="Quantity" name="quantity2" id="quantity2">
<p class="help-block text-danger"></p>
</div>
</div>
</div>
<div class="select">
<div class="col-xs-6">
<div class="form-group">
<select class="selectpicker" name="product3" id="product3" data-width="100%" data-height="100%" data-live-search="true" title="Choose Product" data-style="btn-primary">
<optgroup label="100 Series">
<option>90mm Grey Standard</option>
</optgroup>
</select>
</div>
</div>
</div>
<div class="right-form-column">
<div class="col-xs-6">
<div class="form-group">
<input type="number" class="form-control" placeholder="Quantity" name="quantity3" id="quantity3">
<p class="help-block text-danger"></p>
</div>
</div>
</div>
<div class="form-group">
<textarea class="form-control" placeholder="Additional comments" name="message" id="message"></textarea>
<p class="help-block text-danger"></p>
</div>
</div>
<div class="clearfix"></div>
<div class="col-lg-12 text-center">
<div id="success"></div>
<button type="submit" class="btn btn-xl" name="submit">submit</button>
</div>
</div>
</form>
PHP:
<?php
// check if fields passed are empty
if(empty($_POST['name']) ||
empty($_POST['phone']) ||
empty($_POST['email']) ||
empty($_POST['message']) ||
!filter_var($_POST['email'],FILTER_VALIDATE_EMAIL))
{
echo "No arguments Provided!";
return false;
}
$name = $_POST['name'];
$phone = $_POST['phone'];
$email_address = $_POST['email'];
$message = $_POST['message'];
// create email body and send it
$to = 'myname@mydomain.com'; // PUT YOUR EMAIL ADDRESS HERE
$email_subject = "P Services Contact Form: $name"; // EDIT THE EMAIL SUBJECT LINE HERE
$email_body = "You have received a new message from your website's contact form.\n\n"."Here are the details: From: $name\n Phone: $phone\n E-Mail: $email_address\n Suburb: $suburb\n State: $state\n Post Code: $postcode\n Product: $product1\n Quantity: $quantity1\n Product: $product2\n Quantity: $quantity2\n Product: $product3\n Quantity: $quantity3\n Message:\n $message";
$headers = "From: noreply@yourdomain.com\n";
$headers .= "Reply-To: $email_address";
if(mail($to,$email_subject,$email_body,$headers)){
echo "Mail sent successfully.";
}
else{ echo "Error.";
}
?>