所以我有一个问题,如果我将代码中的“业务”部分保留在没有它的情况下表单不起作用,它就可以了!
<div class="row control-group">
<div class="form-group col-xs-12 floating-label-form-group controls">
<label for="phone">Phone Number</label>
<input type="tel" class="form-control" placeholder="Phone Number" id="phone" required data-validation-required-message="Please enter your phone number.">
<p class="help-block text-danger"></p>
</div>
</div>
<!-- This part breaks the code -->
<div class="row control-group">
<div class="form-group col-xs-12 floating-label-form-group controls">
<label for="business">Promo Code</label>
<input type="text" class="form-control" placeholder="Promo Code" id="business" required data-validation-required-message="Please enter promo code here, if you don't have one enter 0.">
<p class="help-block text-danger"></p>
</div>
</div>
<!-- If I remove this part it works -->
<div class="row control-group">
<div class="form-group col-xs-12 floating-label-form-group controls">
<label for="message">Message</label>
<textarea rows="5" class="form-control" placeholder="Message and Zip code goes here" id="message" required data-validation-required-message="Please enter a message."></textarea>
<p class="help-block text-danger"></p>
</div>
</div>
因此,如果我运行html代码而没有说“它打破了代码”的部分,并且在php端没有“业务”,它运行得很好,我收到了一封电子邮件。只是在启用该字段的情况下,我才收到电子邮件:/
PHP方面:
<?php
// stuff over here
if(empty($_POST['name']) ||
empty($_POST['email']) ||
empty($_POST['phone']) ||
empty($_POST['business']) ||
empty($_POST['message']) ||
!filter_var($_POST['email'],FILTER_VALIDATE_EMAIL))
{
echo "No arguments Provided!";
return false;
}
$name = strip_tags(htmlspecialchars($_POST['name']));
$email_address = strip_tags(htmlspecialchars($_POST['email']));
$phone = strip_tags(htmlspecialchars($_POST['phone']));
$business = strip_tags(htmlspecialchars($_POST['business']));
$message = strip_tags(htmlspecialchars($_POST['message']));
// here goes the email part
$to = 'email@yahoo.com';
$email_subject = "Website Contact Form: $name";
$email_body = "You have received a new message from your website contact form.\n\n"."Here are the details:\n\nName: $name\n\nEmail: $email_address\n\nPhone: $phone\n\nBusiness: $business\n\nMessage:\n$message";
$headers = "From: noreply@site.com"; // This is the email address the generated message will be from. We recommend using something like noreply@yourdomain.com.
$headers .= "Reply-To: $email_address";
mail($to,$email_subject,$email_body,$headers);
return true;
?>
非常感谢任何帮助,提前谢谢!