0

我有一个 PHP 表单,我可以毫无问题地接收输入字段,但是我有许多选项字段似乎没有发送到电子邮件客户端。下面是 HTML 代码和 PHP 脚本..

任何帮助将不胜感激 :)

多谢你们

<form action="/php/send-fast-action-form.php" method="post" name="form">
<div class="fast-action-details">
<input type="text" class="fast_form_name" name="fast_form_name" data-default="Full Name">
<input type="text" class="fast_form_address" name="fast_form_address" data-default="Address">
<input type="text" class="email" name="email" data-default="Postcode">
<input type="text" class="fast_form_landline" name="fast_form_landline" data-default="Landline">
<input type="text" class="fast_form_mobile" name="fast_form_mobile" data-default="Mobile">
<input type="text" class="fast_form_email" name="fast_form_email" data-default="Email">

<div class="fast-action-dropdown">
<select>
    <option value="" disabled="disabled" selected="selected" class="property_type" name="property_type" data-    default="Property Type">Property Type</option>
    <option value="Detached">Detached</option>
    <option value="Semi-Detached">Semi-Detached</option>
    <option value="Mid-Terrace">Mid-Terrace</option>
    <option value="End-Terrace">End-Terrace</option>
    <option value="Apartment/Flat">Apartment/Flat</option>
    <option value="Other">Other</option>   
</select>   

<select>
    <option value="" disabled="disabled" selected="selected" class="number_of_rooms" name="number_of_rooms" data-    default="Number of Bedrooms">Number of Bedrooms</option>
    <option value="1">1</option>
    <option value="2">2</option>
    <option value="3">3</option>
    <option value="4">4</option>
    <option value="5+">5+</option> 
</select>   
</div>

<textarea class="fast_form_reason" name="fast_form_reason" data-default="Reason For Sale">
Reason For Sale
</textarea>

<div class="fast-action-send" onclick="form.submit()">Send</div>
</form>






<?php
if(isset($_POST['email'])) {

    // CHANGE THE TWO LINES BELOW
    $email_to = "your@example.com";

    $email_subject = "Fast Action Form Response";


function changeValue(){
    option document.getElementById('filter').value;

    if(option=="A"){
            document.getElementById('field').value="A Selected";
    }
        else if(option=="B"){
            document.getElementById('field').value="B Selected";
        }

}


    function died($error) {
        // your error code can go here
        echo "We are very sorry, but there were error(s) found with the form you submitted. ";
        echo "These errors appear below.<br /><br />";
        echo $error."<br /><br />";
        echo "Please go back and fix these errors.<br /><br />";
        die();
    }

    // validation expected data exists
    if(!isset($_POST['fast_form_name']) ||
        !isset($_POST['fast_form_address']) ||
        !isset($_POST['email']) ||
        !isset($_POST['fast_form_landline']) ||
        !isset($_POST['fast_form_mobile']) ||
        !isset($_POST['fast_form_email']) ||
        !isset($_POST['fast_form_reason'])) { 
        died('We are sorry, but there appears to be a problem with the form you submitted.');       
    }

    $fast_form_name = $_POST['fast_form_name'];
    $fast_form_address = $_POST['fast_form_address'];
    $email = $_POST['email'];
    $fast_form_landline = $_POST['fast_form_landline'];
    $fast_form_mobile = $_POST['fast_form_mobile']; 
    $email_from = $_POST['fast_form_email'];
    $fast_form_reason = $_POST['fast_form_reason'];

    $error_message = "";

    $string_exp = "/^[A-Za-z .'-]+$/";
  if(!preg_match($string_exp,$fast_form_name)) {
    $error_message .= 'The Name you entered does not appear to be valid.<br />';
  }
  if(strlen($error_message) > 0) {
    died($error_message);
  }
    $email_message = "A user has filled in the Sell And Move On - Fast Action Form, their details are below ..\n\n";

    function clean_string($string) {
      $bad = array("content-type","bcc:","to:","cc:","href");
      return str_replace($bad,"",$string);
    }   

    $email_message .= "Full Name: ".clean_string($fast_form_name)."\n";
    $email_message .= "Address : ".clean_string($fast_form_address)."\n";
    $email_message .= "Postcode: ".clean_string($email)."\n"; 
    $email_message .= "Landline: ".clean_string($fast_form_landline)."\n";
    $email_message .= "Mobile: ".clean_string($fast_form_mobile)."\n"; 
    $email_message .= "Email: ".clean_string($email_from)."\n"; 
    $email_message .= "Reason: ".clean_string($fast_form_reason)."\n";


// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);  
?>

<!-- place your own success html below -->

Successfull HTML Here 

<?php
}
die();
?>
4

3 回答 3

2

我假设这是您遇到问题的第二个选择元素。

它缺少名称属性。另请注意,选项不应具有名称属性。

请参阅此处的示例:http: //www.tizag.com/phpT/examples/formex.php

于 2013-09-26T19:16:06.480 回答
1
<select>
    <option value="" disabled="disabled" selected="selected" class="number_of_rooms" name="number_of_rooms" data-default="Number of Bedrooms">Number of Bedrooms</option>
    <option value="1">1</option>
    <option value="2">2</option>
    <option value="3">3</option>
    <option value="4">4</option>
    <option value="5+">5+</option> 
</select>   

我没有在这个元素上看到 name 属性。尝试:

<select name="my_form_element">
    <option value="" disabled="disabled" selected="selected" class="number_of_rooms" name="number_of_rooms" data-default="Number of Bedrooms">Number of Bedrooms</option>
    <option value="1">1</option>
    <option value="2">2</option>
    <option value="3">3</option>
    <option value="4">4</option>
    <option value="5+">5+</option> 
</select>

注意name="my_form_element"属性。然后通过 PHP 访问它:

$_POST['my_form_element'] 
于 2013-09-26T19:17:57.957 回答
-1

这些线条也不好看。没有理由给一个选项命名,给其他选项命名。这是一个不好的做法。尝试规范化您的代码,使用它会更容易。

<option value="" disabled="disabled" selected="selected" class="property_type" name="property_type" data-default="Property Type">Property Type</option>
<option  id="A" value="A">Detached</option>
<option  id="B" value="B">Semi-Detached</option>
于 2013-09-26T19:21:30.140 回答