PHP赢得';t提交列表选择


PHP won't submit list selection

我一直在成功地使用邮件表单,直到我将"state"字段从文本字段更改为选择/列表。现在php不会发送"state字段"的内容。我需要修改php以适应不同类型的字段吗?这是PHP。

PHP:

<?php
  if(isset($_POST['email'])) {         
    // EDIT THE 2 LINES BELOW AS REQUIRED    
    $email_to = "pecraig@moneymovers.com";    
    $email_subject = "OBM/Mailing List Form";         
    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['first_name']) ||    
      !isset($_POST['last_name']) ||    
      !isset($_POST['email']) ||    
      !isset($_POST['telephone']) ||    
      !isset($_POST['company']) ||    
      !isset($_POST['street']) ||    
      !isset($_POST['city']) ||    
      !isset($_POST['state']) ||    
      !isset($_POST['zip'])) {    
        died('We are sorry, but there appears to be a problem with the form you submitted.');   
    }    

    $first_name = $_POST['first_name']; // required    
    $last_name = $_POST['last_name']; // required    
    $email_from = $_POST['email']; // required    
    $telephone = $_POST['telephone']; // required    
    $company = $_POST['company']; // required    
    $street = $_POST['street']; // required    
    $city = $_POST['city']; // required    
    $state = $_POST['state']; // required    
    $zip = $_POST['zip']; // required       
    $error_message = "";
    $string_exp = "/^[A-Za-z0-9 .'-]+$/";
    if(!preg_match($string_exp,$first_name)) {    
      $error_message .= 'The First Name you entered does not appear to be valid.<br />';   
    }
    if(!preg_match($string_exp,$last_name)) {    
      $error_message .= 'The Last Name you entered does not appear to be valid.<br />';
    }  
    $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+'.[A-Za-z]{2,4}$/';
    if(!preg_match($email_exp,$email_from)) {    
      $error_message .= 'The Email Address you entered does not appear to be valid.<br />';
    }
    if(!preg_match($string_exp,$telephone)) {      
      $error_message .= 'The Telephone Number you entered does not appear to be valid.<br />';    
    }
    if(strlen($error_message) > 0) {    
      died($error_message);    
    }
    $email_message = "This is Response from OBM/Mailing List Page.  If only the first four fields are filled it is a request for an OBM demo - please contact.  If all fileds are filled please contact and enter in database.'n'n";    

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

    $email_message .= "First Name: ".clean_string($first_name)."'n";    
    $email_message .= "Last Name: ".clean_string($last_name)."'n";    
    $email_message .= "Email: ".clean_string($email_from)."'n";    
    $email_message .= "Telephone: ".clean_string($telephone)."'n";    
    $email_message .= "Company: ".clean_string($company)."'n";    
    $email_message .= "Street: ".clean_string($street)."'n";    
    $email_message .= "City: ".clean_string($city)."'n";    
    $email_message .= "State: ".clean_string($state)."'n";    
    $email_message .= "Zip: ".clean_string($zip)."'n";        
    // create email headers    
    $headers = 'From: '.$email_from."'r'n".    
    headers = 'Cc: info@moneymovers.com'."'r'n";    
    'Reply-To: '.$email_from."'r'n" .    
    'X-Mailer: PHP/' . phpversion();
    @mail($email_to, $email_subject, $email_message, $headers);
    header('location: http://moneymovers.com/download.htm');
    ?>
    <!-- include your own success html here -->
    <?php
  }
?>

HTML:

<tr>
  <td width="62" height="12" valign="top" class="text10"><span class="style5">State</span></td>
  <td height="12" valign="top">
    <select name="State" id="State">
      <option selected>AL</option>
      <option>AK</option>
      <option>AZ</option>
      <option>AR</option>
      <option>CA</option>
      <option>CO</option>
      <option>CT</option>
      <option>DE</option>
      <option>D.C.</option>
      <option>FL</option>
      <option>GA</option>
      <option>HI</option>
      <option>ID</option>
      <option>IL</option>
      <option>IN</option>
      <option>IA</option>
      <option>KS</option>
      <option>KY</option>
      <option>LA</option>
      <option>ME</option>
      <option>MD</option>
      <option>MA</option>
      <option>MI</option>
      <option>MN</option>
      <option>MS</option>
      <option>MO</option>
      <option>MT</option>
      <option>NE</option>
      <option>NV</option>
      <option>NH</option>
      <option>NJ</option>
      <option>NM</option>
      <option>NY</option>
      <option>NC</option>
      <option>ND</option>
      <option>OH</option>
      <option>OK</option>
      <option>OR</option>
      <option>PA</option>
      <option>RI</option>
      <option>SC</option>
      <option>SD</option>
      <option>TN</option>
      <option>TX</option>
      <option>UT</option>
      <option>VT</option>
      <option>WA</option>
      <option>WV</option>
      <option>WI</option>
      <option>WY</option>
      <option>AS</option>
      <option>GU</option>
      <option>PR</option>
      <option>VI</option>
    </select>
  </td>
</tr>

编辑:

尝试将<select>列表的名称从"State"更改为"State"。资本化很重要。

我在下面收回我原来的答案
显然"如果未定义,则其默认值为元素的文本内容。"
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/option

原始(过时):

您需要给<select>列表一个name,给<option>一些值:

<select name="state">
  <option value="AL" selected>AL</option>
  ...
</select>


编辑:

此外,在构建电子邮件头时,您似乎将串联与直接变量定义混合在一起。

尝试:

$headers = 'From: '.$email_from."'r'n" .
  'Cc: info@moneymovers.com'."'r'n" .
  'Reply-To: '.$email_from."'r'n" .
  'X-Mailer: PHP/' . phpversion();

$headers = 'From: '.$email_from."'r'n";
$headers .= 'Cc: info@moneymovers.com'."'r'n";
$headers .=  'Reply-To: '.$email_from."'r'n";
$headers .= 'X-Mailer: PHP/' . phpversion();