2012-03-03 52 views
2

这里是我使用的形式:为什么没有被张贴在电子邮件我<select>值

<form action="scripts/contactscript.php" method="post" id="contactform"> 
    <ol> 
    <li> 
     <label for="name">Your Name <span class="red">*</span></label> 
     <input id="name" name="name" class="text" /> 
    </li> 
    <li> 
     <label for="email">Your email <span class="red">*</span></label> 
     <input id="email" name="email" class="text" /> 
    </li> 
    <li> 
     <label for="interested">Interested In <span class="red">*</span></label> 
     <select id="interested" name="interested"> 
     <option value="">-- Please Select --</option> 
     <option value="GeneralInformation">General Information</option> 
     <option value="PurchasingABike">Purchasing A Bike</option> 
     </select> 
    </li> 
    <li> 
     <label for="message">Message <span class="red">*</span></label> 
     <textarea id="message" name="message" rows="6" cols="50"></textarea> 
    </li> 
    <li class="buttons"> 
     <input type="image" name="imageField" id="imageField" src="images/send.gif" class="send" /> 
     <div class="clr"></div> 
    </li> 
    </ol> 
</form> 

,这里是它被张贴到脚本:

<?php 
if(!$_POST) exit; 
$email = $_POST['email']; 

//$error[] = preg_match('/\b[A-Z0-9._%-][email protected][A-Z0-9.-]+\.[A-Z]{2,4}\b/i', $_POST['email']) ? '' : 'INVALID EMAIL ADDRESS'; 
if(!eregi("^[a-z0-9]+([_\\.-][a-z0-9]+)*" ."@"."([a-z0-9]+([\.-][a-z0-9]+)*)+"."\\.[a-z]{2,}"."$",$email)){ 
    $error.="Invalid email address entered"; 
    $errors=1; 
} 

if($errors==1) echo $error; 
else{ 
    $values = array ('name','email','message','interested'); 
    $required = array('name','email','message'); 

    $your_email = "[email protected]"; 
    $email_subject = "Little Bike Riders Message: ".$_POST['subject']; 
    $email_content = "New message:\n\n"; 

    foreach($values as $key => $value){ 
     if(in_array($value,$required)){ 
      if(empty($_POST[$value])) { echo 'PLEASE FILL IN REQUIRED FIELDS'; exit; } 
     } 
     $email_content .= $value.': '.$_POST[$value]."\n\n" ; 
    } 


    if(@mail($your_email,$email_subject,$email_content)) { 
     echo 'Message sent!'; 
    } else { 
     echo 'ERROR!'; 
    } 
} 
?> 

这里是所示在当发送的电子邮件:

新信息:

名称:乔恩·哈丁

电子邮件:[email protected]

消息:测试

感兴趣:

+0

谢谢Michael! – 2012-03-03 18:54:35

+0

'$ email_content'是什么样的?当'var_dump($ _ POST)''时,你看到'interested'的值吗? – 2012-03-03 18:58:09

+0

我在文章 – 2012-03-03 19:01:56

回答

1

提交表单具有期权价值""时,您已经选择了默认项-- Please Select --并正在显示在你的电子邮件。我在本地尝试过你的例子,如果我选择其中一个工作的其他选项。

编辑:

您正在使用下面的代码提交表单:

jQuery(document).ready(function(){ 
    $('#contactform').submit(function(){     
     var action = $(this).attr('action'); 
     $.post(action, { 
      name: $('#name').val(), 
      email: $('#email').val(), 
      subject: $('#subject').val(), 
      message: $('#message').val() 
     }, 
      function(data){ 
       $('#contactform #submit').attr('disabled',''); 
       $('.response').remove(); 
       $('#contactform').before('<p class="response">'+data+'</p>'); 
       $('.response').slideDown(); 
       if(data=='Message sent!') $('#contactform').slideUp(); 
      } 
     ); 
     return false; 
    }); 
}); 

你忘了感兴趣的元素interested: $('#interested').val()的价值添加到您传递给目标$ .post方法。

+0

http://littlebikeriders.com/new/contact.php - 给它一个镜头在这里 – 2012-03-03 19:13:43

+0

我已经改变了空字符串,它仍然不能在服务器上工作 – 2012-03-03 19:14:03

+0

可能有服务器设置,这是冲突? – 2012-03-03 19:15:36

相关问题