空PHP联系表单= 500错误

时间:2016-02-13 13:41:56

标签: php forms twitter-bootstrap email

之前我已经完成了不少联系表单,但由于某种原因,如果任何字段为空,那么我会收到错误500页的说法 " 500 - 内部服务器错误。 您正在查找的资源存在问题,无法显示。"

奇怪的是,表单仍然发送,无论输入什么信息,所以提交功能和资产似乎都在起作用。

我已经尝试将变量设置为在表单之前有一个值,并且在提交之后(添加""。$ variablename)因此它们不是空的但它不是&# 39;似乎工作。我使用带有说明的表单填写每个字段,但它是一个网络查询表单,所以我希望客户能够添加他们想要的多少(所以不要需要表格验证,例如)。

我使用bootstrap作为网站的框架。  有任何想法吗??代码

HTML

  <div class="modal fade" id="modalContact" role="dialog">

    <div class="modal-dialog">
        <div class="modal-content" id="form">

        <div class="modal-header">
            <h4>Not sure what you need?</h4><p>Fill in form below as you can and we will get in touch with some suggestions.  Please ensure you fill in every field, if you're not sure, say you're not sure!</p>

        </div>

        <div class="modal-body">

            <form action="scripts/contactscript.php" method="post" class="form-horizontal">
                <div class="form-group">
                    <label for="name" class="col-md-3 col-xs-12 col-lg-3 col-sm-3">Name: </label>
                    <div class="col-md-9 col-xs-12 col-lg-9 col-sm-9">
                        <input type="text" class="form-control" id="name"  name="name" placeholder="Please give us your full name">
                    </div>
                </div>

                <div class="form-group">
                    <label for="email" class="col-md-3 col-xs-12 col-lg-3 col-sm-3">Email: </label>
                    <div class="col-md-9 col-xs-12 col-lg-9 col-sm-9">
                        <input type="email" class="form-control" id="email" name="email" placeholder="Example@youremail.com">
                    </div>
                </div>

                <div class="form-group">
                    <label for="url" class="col-md-3 col-xs-12 col-lg-3 col-sm-3">Website:    <span class="glyphicon glyphicon-question-sign" data-toggle="tooltip" data-placement="right" title="If you already have a website please enter it here. Alternatively you may want to enter a link to a site that you like or feel would help us better understand your aims, this could be for content, styles or interactive sections.  Please let us know any specifics in the 'extra' section below"></span> </label>
                    <div class="col-md-9 col-xs-12 col-lg-9 col-sm-9">
                        <input type="text" class="form-control" id="url" name="url" placeholder="www.yourexample.com">
                    </div>

                </div>

                <div class="form-group">
                    <label for="background" class="col-md-3 col-xs-12 col-lg-3 col-sm-3">What: <span class="glyphicon glyphicon-question-sign" data-toggle="tooltip" data-placement="right" title="Let us know what you want from your website.  Is it a business, a blog, for fun? try and keep the description short using keywords"></span></label>
                    <div class="col-md-9 col-xs-12 col-lg-9 col-sm-9">
                        <textarea class="form-control" name="bkgrd" placeholder="Tell us about what you want to achieve" rows="3" id="background"></textarea>
                    </div>
                </div>

                <div class="form-group">
                    <label for="content" class="col-md-3 col-xs-12 col-lg-3 col-sm-3">Content: <span class="glyphicon glyphicon-question-sign" data-toggle="tooltip" data-placement="right" title="What tools do you need your website to have? "></span></label>
                    <div class="col-md-9 col-xs-12 col-lg-9 col-sm-9">
                        <label class="checkbox ">
                            <input type="checkbox" name="content[]" id="contact" value="contact form">Contact form
                        </label>
                        <label class="checkbox ">
                            <input type="checkbox" name="content[]" id="booking" value="booking system">Booking system/interactive calender
                        </label>
                        <label class="checkbox ">
                            <input type="checkbox" name="content[]" id="commerce" value="ecommerce"> E-commerce/secure check out
                        </label>
                        <label class="checkbox">
                            <input type="checkbox" name="content[]" id="cms" value="cms"> Content management system <span class="glyphicon glyphicon-question-sign" data-toggle="tooltip" data-placement="right" title="Having a content management system means users (or you) can update the website via a log on function, similar to a blog.  Without this you may need someone to update your website manually"></span>
                        </label>
                        <label class="checkbox">
                            <input type="checkbox" name="content[]" id="users" value="profiles"> Secure log in/user profiles
                        </label>
                        <label class="checkbox ">
                            <input type="checkbox" name="content[]" id="social" value="social"> Embedded social media
                        </label>
                        <label class="checkbox ">
                            <input type="checkbox" name="content[]" id="none" value="none"> None
                        </label>
                        <textarea class="form-control" rows="2" placeholder="Let us know any specific ideas you may have in mind or have discovered on other sites while browsing"></textarea>

                    </div>
                </div>

                <div class="form-group">
                    <label for="other" class="col-md-3 col-xs-12 col-lg-3 col-sm-3">Anything else? </label>
                    <div class="col-md-9 col-xs-12 col-lg-9 col-sm-9">
                        <textarea id="other" name="other" class="form-control" rows="2" placeholder="Anything else you feel might be useful" ></textarea>
                    </div>
                </div>

                <button type="submit" class="btn-default" name="submit" value="submit">Submit</button>
            </form>

        </div>


    </div>
    </div>

</div>

PHP(不在同一页面上)

    if(isset($_POST['submit'])) {
    $to = "noreply@mywebsite.com";
    $subject = "Website Enquiry";
    $name = $_POST['name'];
    $email = $_POST['email'];
    $url = $_POST['url'];
    $bkgrd = $_POST['bkgrd'];
    $content = implode(": ", $_POST['content']);
    $other = $_POST['other'];


}

$sub2 = "Thank you for your enquiry";
$msg= "Thank you for your enquiry.  We have received your contact form and will be in touch soon to discuss this further\n


Thanks\n

;


$message = "From:  $name\n Email: $email\n URL: $url\n Overview: $bkgrd\n Content: $content \n Other: $other   ";

mail($email, $sub2, $msg);

if(mail($to, $subject, $message)){

    header("location: http://www.mywebsite.com");


}else{


    header("location: http://www.mywebsite.com");
}

0 个答案:

没有答案