php表单和下拉选项的问题

时间:2016-12-10 08:44:00

标签: php forms

我不是开发人员或程序员,但我想知道是否有人可以帮助我。我试图设置一个带有下拉选项的PHP表单,但它不再发送。曾经有一段时间我可以发送它,但电子邮件是空白的,电子邮件中没有出现任何选择。我究竟做错了什么?提前谢谢,感谢您的帮助。

<form method="post" action="inquiry.php">
                            <div class="select-wrapper clearfix">
                                <div class="col-md-6">
                                    <div class="min-price select-dropdown">
                                        <div class="my-dropdown min-price-dropdown min-dropdown">
                                            <select name="min-year" class="css-dropdowns" tabindex="1" >
                                                <option value="">Min Year</option>
                                                <option>2016</option>
                                                <option>2015</option>
                                                <option>2014</option>
                                                <option>2013</option>
                                                <option>2012</option>
                                                <option>2011</option>
                                                <option>2010</option>
                                                <option>2009</option>
                                                <option>2008</option>
                                                <option>2007</option>
                                                <option>2006</option>
                                                <option>2005</option>
                                                <option>2003</option>
                                                <option>2002</option>
                                                <option>2001</option>
                                                <option>2000</option>
                                                <option>1999</option>
                                                <option>1998</option>
                                                <option>1997</option>
                                                <option>1996</option>
                                                <option>1995</option>
                                                <option>1994</option>
                                                <option>1993</option>
                                                <option>1992</option>
                                                <option>1991</option>
                                                <option>1990</option>
                                                <option>1989</option>
                                                <option>1988</option>
                                                <option>1987</option>
                                                <option>1986</option>
                                                <option>1985</option>
                                                <option>1984</option>
                                                <option>1983</option>
                                                <option>1982</option>
                                                <option>1981</option>
                                                <option>1980</option>
                                                <option>1979</option>
                                                <option>1978</option>
                                                <option>1977</option>
                                                <option>1976</option>
                                                <option>1975</option>
                                                <option>1974</option>
                                                <option>1973</option>
                                                <option>1972</option>
                                                <option>1971</option>
                                                <option>1970</option>
                                                <option>1969</option>
                                                <option>1968</option>
                                                <option>1967</option>
                                                <option>1966</option>
                                                <option>1965</option>
                                                <option>1964</option>
                                                <option>1963</option>
                                                <option>1962</option>
                                                <option>1961</option>
                                                <option>1960</option>
                                            </select>
                                        </div>
                                        <span class="my-dropdown">to</span>
                                        <div class="my-dropdown max-price-dropdown min-dropdown">
                                            <select name="max-year" class="css-dropdowns" tabindex="1" >
                                                <option value="">Max Year</option>
                                                <option>2016</option>
                                                 <option>2015</option>
                                                <option>2014</option>
                                                <option>2013</option>
                                                <option>2012</option>
                                                <option>2011</option>
                                                <option>2010</option>
                                                <option>2009</option>
                                                <option>2008</option>
                                                <option>2007</option>
                                                <option>2006</option>
                                                <option>2005</option>
                                                <option>2003</option>
                                                <option>2002</option>
                                                <option>2001</option>
                                                <option>2000</option>
                                                <option>1999</option>
                                                <option>1998</option>
                                                <option>1997</option>
                                                <option>1996</option>
                                                <option>1995</option>
                                                <option>1994</option>
                                                <option>1993</option>
                                                <option>1992</option>
                                                <option>1991</option>
                                                <option>1990</option>
                                                <option>1989</option>
                                                <option>1988</option>
                                                <option>1987</option>
                                                <option>1986</option>
                                                <option>1985</option>
                                                <option>1984</option>
                                                <option>1983</option>
                                                <option>1982</option>
                                                <option>1981</option>
                                                <option>1980</option>
                                                <option>1979</option>
                                                <option>1978</option>
                                                <option>1977</option>
                                                <option>1976</option>
                                                <option>1975</option>
                                                <option>1974</option>
                                                <option>1973</option>
                                                <option>1972</option>
                                                <option>1971</option>
                                                <option>1970</option>
                                                <option>1969</option>
                                                <option>1968</option>
                                                <option>1967</option>
                                                <option>1966</option>
                                                <option>1965</option>
                                                <option>1964</option>
                                                <option>1963</option>
                                                <option>1962</option>
                                                <option>1961</option>
                                                <option>1960</option>
                                            </select>
                                        </div>
                                    </div>
                                </div>
                                <div class="col-md-6">
                                    <div class="min-price select-dropdown">
                                        <div class="my-dropdown min-price-dropdown min-dropdown">
                                            <select name="min-price" class="css-dropdowns" tabindex="1" >
                                                <option value="">Min Price</option>
                                                <option>0</option>
                                                <option>&lt; 10,000</option>
                                                <option>&lt; 20,000</option>
                                                <option>&lt; 30,000</option>
                                                <option>&lt; 40,000</option>
                                                <option>&lt; 50,000</option>
                                                <option>&lt; 60,000</option>
                                                <option>&lt; 70,000</option>
                                                <option>&lt; 80,000</option>
                                                <option>&lt; 90,000</option>
                                                <option>&lt; 100,000</option>
                                                <option>&lt; 120,000</option>
                                                <option>&lt; 150,000</option>
                                            </select>
                                        </div>
                                        <span class="my-dropdown">to</span>
                                        <div class="my-dropdown max-price-dropdown min-dropdown">
                                            <select name="max-price" class="css-dropdowns" tabindex="1" >
                                                <option value="">Max Price</option>
                                                <option>0</option>
                                                <option>&lt; 10,000</option>
                                                <option>&lt; 20,000</option>
                                                <option>&lt; 30,000</option>
                                                <option>&lt; 40,000</option>
                                                <option>&lt; 50,000</option>
                                                <option>&lt; 60,000</option>
                                                <option>&lt; 70,000</option>
                                                <option>&lt; 80,000</option>
                                                <option>&lt; 90,000</option>
                                                <option>&lt; 100,000</option>
                                                <option>&lt; 120,000</option>
                                                <option>&lt; 150,000</option>
                                            </select>
                                        </div>
                                    </div>
                                </div>
                            </div>

                            <div class="select-wrapper clearfix">
                                <div class="col-md-6">
                            <div class="min-price select-dropdown">
                                        <div class="my-dropdown min-price-dropdown min-dropdown">
                                            <select name="min-month" class="css-dropdowns" tabindex="1" >
                                                <option value="">Min Monthly Payment</option>
                                                <option>0</option>
                                                <option>0-500</option>
                                                <option>500-1000</option>
                                                <option>1000+</option>

                                            </select>
                                        </div>
                                        <span class="my-dropdown">to</span>
                                        <div class="my-dropdown max-price-dropdown min-dropdown">
                                            <select name="max-month" class="css-dropdowns" tabindex="1" >
                                                <option value="">Max Monthly Payment</option>
                                                <option>0</option>
                                                <option>0-500</option>
                                                <option>500-1000</option>
                                                <option>1000+</option>

                                            </select>
                                        </div>
                                        </div>
                                        </div>


                            <div class="select-wrapper clearfix">
                                <div class="col-md-6">
                                    <div class="my-dropdown make-dropdown">
                                        <select name="body_style" class="css-dropdowns" tabindex="1" >
                                            <option value="">Body Style</option>
                                            <option>Cargo</option>
                                            <option>Compact</option>
                                            <option>Convertible</option>
                                            <option>Coupe</option>
                                            <option>Hatchback</option>
                                            <option>Minivan</option>
                                            <option>Sedan</option>
                                            <option>SUV</option>
                                            <option>Truck</option>
                                            <option>Van</option>
                                            <option>Wagon</option>
                                        </select>
                                    </div>
                                </div>
                                <div class="col-md-6">
                                    <div class="min-price select-dropdown">
                                        <div class="my-dropdown min-price-dropdown min-dropdown">
                                            <select name="min-mileage" class="css-dropdowns" tabindex="1" >
                                                <option value="">Min Mileage</option>
                                                <option>0</option>
                                                <option>&lt; 10,000</option>
                                                <option>&lt; 20,000</option>
                                                <option>&lt; 30,000</option>
                                                <option>&lt; 40,000</option>
                                                <option>&lt; 50,000</option>
                                                <option>&lt; 60,000</option>
                                                <option>&lt; 70,000</option>
                                                <option>&lt; 80,000</option>
                                                <option>&lt; 90,000</option>
                                                <option>&lt; 100,000</option>
                                                <option>&lt; 120,000</option>
                                                <option>&lt; 150,000</option>
                                            </select>
                                        </div>
                                        <span class="my-dropdown">to</span>
                                        <div class="my-dropdown max-price-dropdown min-dropdown">
                                            <select name="max-mileage" class="css-dropdowns" tabindex="1" >
                                                <option value="">Max Mileage</option>
                                                <option>0</option>
                                                <option>&lt; 10,000</option>
                                                <option>&lt; 20,000</option>
                                                <option>&lt; 30,000</option>
                                                <option>&lt; 40,000</option>
                                                <option>&lt; 50,000</option>
                                                <option>&lt; 60,000</option>
                                                <option>&lt; 70,000</option>
                                                <option>&lt; 80,000</option>
                                                <option>&lt; 90,000</option>
                                                <option>&lt; 100,000</option>
                                                <option>&lt; 120,000</option>
                                                <option>&lt; 150,000</option>
                                            </select>
                                        </div>
                                    </div>
                                </div>
                            </div>



                            <div class="select-wrapper clearfix">
                                <div class="col-md-6">
                                    <div class="my-dropdown make-dropdown">
                                        <select name="make" class="css-dropdowns" tabindex="1" >
                                            <option value="">Make</option>
                                            <option>Lorem</option>
                                            <option>ipsum</option>
                                            <option>dolor</option>
                                            <option>sit</option>
                                            <option>amet</option>
                                        </select>
                                    </div>
                                </div>
                                <div class="col-md-6">
                                    <div class="my-dropdown make-dropdown">
                                        <select name="transmission" class="css-dropdowns" tabindex="1" >
                                            <option value="">Transmission</option>
                                            <option>Automatic</option>
                                            <option>Manual</option>
                                        </select>
                                    </div>
                                </div>
                            </div>
                            <div class="select-wrapper clearfix">
                                <div class="col-md-6">
                                    <div class="my-dropdown make-dropdown">
                                        <select name="model" class="css-dropdowns" tabindex="1" >
                                            <option value="">Model</option>
                                            <option>Lorem</option>
                                            <option>ipsum</option>
                                            <option>dolor</option>
                                            <option>sit</option>
                                            <option>amet</option>
                                        </select>
                                    </div>
                                </div>

                            </div>
                            <div class="clear"></div>
                            <div class="select-wrapper clearfix">
                                <div class="form-element clearfix">

                                </div>
                                <div class="form-element">

                                </div>
                                <div class="form-element">

                                </div>

                                <br>
                                <div class="form-element">
                                    <input type="submit" value="Find My New Vehicle" class="find_new_vehicle pull-right md-button">
                                </div>
                            </div>
                        </form>

这是我的php文件。

<?php
if(!isset($_POST['submit']))
{
//This page should not be accessed directly. Need to submit the form.

}

$name = $_POST['name'];
$visitor_email = $_POST['email'];
$message = $_POST['min-year'];
$message = $_POST['max-year'];
$message = $_POST['min-price'];
$message = $_POST['max-price'];
$message = $_POST['min-month'];
$message = $_POST['max-month'];
$message = $_POST['body_style'];
$message = $_POST['min-mileage'];
$message = $_POST['max-mileage'];
$message = $_POST['model'];
$message = $_POST['transmission'];
$message = $_POST['make'];






$email_from = 'ericwallace349@gmail.com';//<== update the email address
$email_subject = "New Form submission";
$email_body = "You have received a new message from the user $name.\n".
"Here is the message:\n $message".

"$email"
"$name"
"$min-year"
"$max-year"
"$min-price"
"$max-price"
"$min-month"






$to = "ericwallace349@gmail.com";//<== update the email address
$headers = "From: $email_from \r\n";
$headers .= "Reply-To: $visitor_email \r\n";
//Send the email!
mail($to,$email_subject,$email_body,$headers);
//done. redirect to thank-you page.
header('Location: home.html');


// Function to validate against any email injection attempts
function IsInjected($str)
{
$injections = array('(\n+)',
          '(\r+)',
          '(\t+)',
          '(%0A+)',
          '(%0D+)',
          '(%08+)',
          '(%09+)'
          );
$inject = join('|', $injections);
$inject = "/$inject/i";
if(preg_match($inject,$str))
{
return true;
}
else
{
return false;
}
}

?> 

2 个答案:

答案 0 :(得分:0)

您的value中没有attribute option

 <select name="max-year" class="css-dropdowns" tabindex="1" >
     <option value="">Max Year</option>
     <option value="2016">2016</option><!--add value to all the options-->
     <!--add other options with value-->
</select>

value attribute添加到所有option代码

答案 1 :(得分:0)

您提供的代码中存在很多错误。您可以尝试使用以下方法修复其中一些:

//--- get forms values
$name = $_POST['name'];
$visitor_email = $_POST['email'];
$min-year = $_POST['min-year'];
$max-year = $_POST['max-year'];
$min-price = $_POST['min-price'];
$max-price = $_POST['max-price'];
$min-month = $_POST['min-month'];
$max-month = $_POST['max-month'];
$body_style = $_POST['body_style'];
$min-mileage = $_POST['min-mileage'];
$max-mileage = $_POST['max-mileage'];
$model = $_POST['model'];
$transmission = $_POST['transmission'];
$make = $_POST['make'];


//--- format message and email headers
$email_from = 'ericwallace349@gmail.com';//<== update the email address
$email_subject = "New Form submission";
$email_body = "You have received a new message from the user {$name}.\n".
"Here is the message:\n".
Email : {$email}\n
Name : {$name}\n
Min-Year : {$min-year}\n
Max-Year : {$max-year}\n
Min-Price : {$min-price}\n
Max-Price : {$max-price}\n
Min-Month : {$min-month}";

$to = "ericwallace349@gmail.com";//<== update the email address
$headers = "From: $email_from \r\n";
$headers .= "Reply-To: $visitor_email \r\n";

//---Send the email!
mail($to,$email_subject,$email_body,$headers);

//--- done. redirect to thank-you page.
header('Location: home.html');