2013-09-26 73 views
0

我有一個PHP表單,我接收沒有問題的輸入字段,但是我有一些選項字段似乎沒有發送到電子郵件客戶端。下面是HTML代碼,同時也PHP腳本..以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 = "[email protected]"; 

    $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(); 
?> 
+0

PHP在哪裏? –

回答

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'] 
+0

那麼,我將需要兩個下拉菜單組的名稱正確?你可以看到這個鏈接的進展http://sellandmoveon.co.uk謝謝你們!非常感謝您的幫助! –

+0

@LiamHodnett:是的,您需要在