预订表格PHP无效

时间:2015-10-31 15:21:39

标签: php html forms email

我正在尝试在我的网站上发送一个关于预订的电子邮件。但我无法解决我在PHP中的错误,非常初学PHP,所以不知道我哪里出错了。

在服务器上测试表单时,我没有收到任何电子邮件。

<?php 

$firstname = $_post['firstname'];
$lastname = $_post['lastname'];
$bandname = $_post['bandname'];
$email = $_post['email'];
$phoneno = $_post['phoneno'];
$startday = $_post['start_day'];
$startmonth = $_post['start_month'];
$starthour = $_post['start_hour'];
$startminute = $_post['start_minute'];
$endday = $_post['end_day'];
$endmonth = $_post['end_month'];
$endhour = $_post['end_hour'];
$endminute = $_post['end_minute'];
$extras = $_post['extras'];

$to = "some@emailaddress.com";
$subject = "New Message";

mail ($to, $subject, $firstname . $lastname, $bandname, $email, $phoneno, $start_day . $start_month, $start_hour . $start_minute, $end_day . $end_month, $end_hour . $end_minute, $extras);
?>

我的表单的HTML:

                       <form action="form.php" class="appnitro" id="form_1062945" method="post" name="form_1062945" style="display: inline-block;">
                            <div class="form_description medium-8 small-10 columns medium-centered small-centered" style="margin-bottom:45px">
                                <p>
                                    Please complete the form below to send us details of the booking you would like to make, we will then get back to you within one business day to confirm your booking.
                                </p>
                            </div>

                            <ul>
                                <li class="small-6 columns" id="li_1">
                                    <label class="description" for="element_1">First Name</label>
                                    <div>
                                        <input class="element text medium" id="element_1" maxlength="255" name="firstname" type="text" value="">
                                    </div>
                                </li>

                                <li class="small-6 columns" id="li_2">
                                    <label class="description" for="element_2">Last Name</label>
                                    <div>
                                        <input class="element text medium" id="element_2" maxlength="255" name="lastname" type="text" value="">
                                    </div>
                                </li>

                                <li class="small-6 columns" id="li_3">
                                    <label class="description" for="element_3">Company/band/artist</label>
                                    <div>
                                        <input class="element text medium" id="element_3" maxlength="255" name="bandname" type="text" value="">
                                    </div>
                                </li>

                                <li class="small-6 columns" id="li_8">
                                    <label class="description" for="element_8">Email</label>
                                    <div>
                                        <input class="element text medium" id="element_8" maxlength="255" name="email" type="text" value="">
                                    </div>
                                </li>

                                <li class="small-6 end columns" id="li_4">
                                    <label class="description" for="element_4">Phone number</label>
                                    <div>
                                        <input class="element text medium" id="element_4" maxlength="255" name="phoneno" type="text" value="">
                                    </div>
                                </li>

                                <div class="row">
                                    <div class="small-12 columns">

                                        <li class="small-12 columns text-left" id="li_11">
                                            <label class="description" for="element_11_1">Which space(s) are you interested in?</label>

                                            <div class="line-boxes">
                                                <span>
                                                    <input class="element checkbox" id="element_11_1" name="studio_1" type="checkbox" value="1"> 
                                                    <label class="choice" for="element_11_1">Studio 1</label>
                                                </span>
                                            </div>

                                            <div class="line-boxes">
                                                <span><input class="element checkbox" id="element_11_2" name="studio_2" type="checkbox" value="1"> 
                                                    <label class="choice" for="element_11_2" style="margin-bottom:20px">Studio 2</label>
                                                </span>
                                            </div>

                                        </li>

                                    </div>
                                </div>

                                <li class="small-12 medium-6 columns lose-pad" id="li_6">

                                    <label class="description" for="element_6_1">Start Date</label>

                                    <span class="small-6 columns">
                                        <input class="element text" id="element_6_1" maxlength="2" name="start_day" size="2" type="text" value=""> 
                                        <label for="element_6_1" style="font-size:10px">DD</label>
                                    </span>

                                    <span class="small-6 columns">
                                        <input class="element text" id="element_6_2" maxlength="2" name="start_month" size="2" type="text" value=""> 
                                        <label for="element_6_2" style="font-size:10px">MM</label>
                                    </span>

                                </li>

                                <li class="medium-6 small-12 columns lose-pad" id="li_5">

                                    <label class="description" for="element_5_1">Start Time</label> 

                                    <span class="small-6 columns">
                                        <input class="element text" id="element_5_1" maxlength="2" name="start_hour" size="2" type="text" value=""> 
                                        <label for="element_5_1" style="font-size:10px">HH</label>
                                    </span> 

                                    <span class="small-6 columns">
                                        <input class="element text" id="element_5_2" maxlength="2" name="start_minute" size="2" type="text" value=""> 
                                        <label for="element_5_2" style="font-size:10px">MM</label>
                                    </span>

                                </li>

                                <li class="small-12 medium-6 columns lose-pad" id="li_9">

                                    <label class="description" for="element_9_2">End Date</label> 

                                    <span class="small-6 columns">
                                        <input class="element text" id="element_9_2" maxlength="2" name="end_day" size="2" type="text" value=""> 
                                        <label for="element_9_2" style="font-size:10px">DD</label>
                                    </span> 

                                    <span class="small-6 columns">

                                        <input class="element text" id="element_9_1" maxlength="2" name="end_month" size="2" type="text" value=""> 
                                        <label for="element_9_1" style="font-size:10px">MM</label>
                                    </span> 

                                </li>

                                <li class="medium-6 small-12 columns lose-pad" id="li_7">

                                    <label class="description" for="element_7_1">End Time</label> <span class="small-6 columns">

                                    <input class="element text" id="element_7_1" maxlength="2" name="end_hour" size="2" type="text" value=""> 
                                    <label for="element_7_1" style="font-size:10px">HH</label>
                                    </span> 

                                    <span class="small-6 columns">
                                        <input class="element text" id="element_7_2" maxlength="2" name="end_minute" size="2" type="text" value=""> 
                                        <label for="element_7_2" style="font-size:10px">MM</label>
                                    </span>

                                </li>

                                <li class="small-12 columns text-left" id="li_12">

                                    <label class="description" for="element_12_1" style="margin-top:20px">Do you require or interested in any of the following additional services?</label> 
                                    <div class="line-boxes" style="margin-top:20px">
                                        <span><input class="element checkbox" id="element_12_1" name="console_wedges" type="checkbox" value="1"> 
                                            <label class="choice" for="element_12_1">House monitor console and wedges?</label>
                                        </span>
                                    </div>

                                    <div class="line-boxes">
                                        <span>
                                            <input class="element checkbox" id="element_12_2" name="iem" type="checkbox" value="1"> 
                                            <label class="choice" for="element_12_2">IEM System rental?</label>
                                        </span>
                                    </div>

                                    <div class="line-boxes">
                                        <span>
                                            <input class="element checkbox" id="element_12_3" name="chairs" type="checkbox" value="1"> 
                                            <label class="choice" for="element_12_3">Chairs?</label>
                                        </span>
                                    </div>

                                    <div class="line-boxes">
                                        <span>
                                            <input class="element checkbox" id="element_12_4" name="stools" type="checkbox" value="1"> 
                                            <label class="choice" for="element_12_4">Stools?</label>
                                        </span>
                                    </div>

                                    <div class="line-boxes">
                                        <span>
                                            <input class="element checkbox" id="element_12_5" name="backline" type="checkbox" value="1"> 
                                            <label class="choice" for="element_12_5">Backline rental?</label>
                                        </span>
                                    </div>

                                    <div class="line-boxes">
                                        <span>
                                            <input class="element checkbox" id="element_12_6" name="transport" type="checkbox" value="1"> 
                                            <label class="choice" for="element_12_6" style="margin-bottom:30px">Transport of equipment to or from Ritz</label>                                              </span>
                                    </div>

                                </li>

                                <li class="small-12 columns" id="li_10">

                                    <label class="description" for="element_10">Anything else we should know to help assist with your booking?</label>

                                    <div>
                                        <textarea class="element textarea small" id="element_10" name="extras"></textarea>
                                    </div>
                                </li>

                                <li class="buttons small-6 columns small-centered">
                                    <input name="form_id" type="hidden" value="1062945">
                                    <input class="button_text" id="saveForm" name="submit" type="submit" value="Submit">
                                </li>

                            </ul>
                        </form>

1 个答案:

答案 0 :(得分:3)

首先,您的所有$_post都不正确。

这是一个超级全球,必须读作$_POST

然后你在mail()函数中注入了太多参数。

请阅读手册:

您的服务器可能未设置为捕获并显示/记录错误/通知/警告。

使用错误报告后,会向您发出许多通知。

error reporting添加到文件的顶部,这有助于查找错误。

<?php 
error_reporting(E_ALL);
ini_set('display_errors', 1);

// rest of your code

旁注:只应在暂存时进行显示错误,而不是生产。