Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
部分PHP表单不工作_Php_Html_Forms - Fatal编程技术网

部分PHP表单不工作

部分PHP表单不工作,php,html,forms,Php,Html,Forms,因此,我有一个问题,如果我在代码中保留“业务”部分,那么表单如果没有它就不能工作,它就可以工作 <div class="row control-group"> <div class="form-group col-xs-12 floating-label-form-group controls"> <label for="phone">

因此,我有一个问题,如果我在代码中保留“业务”部分,那么表单如果没有它就不能工作,它就可以工作

    <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;            
?>


非常感谢您的帮助,提前谢谢

如果没有,则输入0
0
视为空。如果这不是您所说的“代码”中断代码的意思,请详细说明。您的输入中没有一个具有“名称”属性。我不知道它是如何工作的。@chris85我把0改成了无,仍然不起作用。我想我跳得太快了。如果这不是您的实际代码,请参阅@Barmar的注释和/或更新代码。