PHP表单适用于IE,但不适用于Chrome或Firefox

时间:2013-10-24 18:13:46

标签: php forms google-chrome email firefox

好的,这么相当直接的php联系表格。它提交并发送数据,并将用户带到感谢页面。但是在google chrome和firefox中,我的用户都会被带到感谢页面,但他们的表单数据不会发送到电子邮件。
这是我正在使用的代码:
在一个页面上填写表格数据

<table width="400" border="0" align="center" cellpadding="0" cellspacing="1">
<tr>
<td><form name="form1" method="post" action="send_wl.php">
<table width="100%" border="0" cellspacing="1" cellpadding="3">
<tr>
<td width="16%">First Name</td>
<td width="2%">:</td>
<td width="82%"><input name="name" type="text" id="name" size="50"></td>
</tr>
<tr>
<tr>
<td width="16%">Last Name</td>
<td width="2%">:</td>
<td width="82%"><input name="lastname" type="text" id="lastname" size="50"></td>
</tr>
<tr>
<td>Address</td>
<td>:</td>
<td><textarea name="address" cols="50" rows="4" id="address"></textarea></td>
</tr>
<tr>
<td>Date of Birth</td>
<td>:</td>
<td><input name="dob" type="date" id="dob" size="50"></td>
</tr>
<tr>
<td>Health Care Number</td>
<td>:</td>
<td><input name="phn" type="text" id="phn" size="50"></td>
</tr>
<tr>
<td>Phone</td>
<td>:</td>
<td><input name="ac" type="text" id="ac" size="3"><input name="phone" type="text" id="phone" size="7"></td>
</tr>
<tr>
<td>Email</td>
<td>:</td>
<td><input name="email" type="text" id="email" size="50"></td>
</tr>
<tr>
<td>Comments</td>
<td>:</td>
<td><textarea name="comment" cols="50" rows="4" id="comment"></textarea></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td><input type="submit" name="Submit" value="Submit"> <input type="reset" name="Submit2" value="Reset"></td>
</tr>
</table>
</form>

另一个页面上的php脚本“send_wl.php”

<?php 
    $to = "ouremail@gmail.com";
    $from = $_POST['email'] ; 
    $name = $_POST['name'] ; 
    $headers = "From: $from"; 
    $subject = "New Patient Data"; 

    $fields = array(); 
    $fields["name"] = "name";
    $fields["lastname"} = "lastname"; 
    $fields["address"] = "address"; 
    $fields["email"] = "email";
    $fields["ac"] = "ac"; 
    $fields["phone"] = "phone"; 
    $fields["dob"] = "dob";
    $fields["phn"] = "phn";
    $fields["comment"] = "comment"; 

    $body = "We have received the following information:\n\n"; foreach($fields as $a => $b){    $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); } 

    $headers2 = "From: noreply@ourwebsite.com"; 
    $subject2 = "Thank you for contacting us"; 
    $autoreply = "Thank you for contacting us. Somebody will get back to you as soon as possible, usualy within 48 hours. If you have any more questions, please consult our website at www.ourwebsite.com";


    if($from == '') {print "You have not entered an email, please go back and try again";
    } else { 
        if($name == '') {print "You have not entered a name, please go back and try again";
        } else { 
            $send = mail($to, $subject, $body, $headers); 
            }
            if($send) 
                {header( "Location: http://www.thewebsite.com/thankyou.html" );} 
            else 
                {print "We encountered an error sending your mail, please notify mailreciepient@gmail.com"; } 
        }
    }
?>

我已经对网站进行了所有建议的更改,但此表单仍然无效。

我是否也应该从$ fields [“lastname”] =“lastname”中删除=“lastname”我知道这似乎是一个愚蠢的问题,但我老老实实地把头发拉出来了。

2 个答案:

答案 0 :(得分:1)

PHP不依赖于浏览器,它是服务器,因此只要同一服务器正在运行,输出就会相同。

您的问题实际上就是您的代码。

所有对$ fields的引用都需要:$ fields [“dob”]因为它是一个哈希映射。这样在获取数据时,它会正确地执行...因为在搜索时你的密钥是错误的。

if($from == '') {
  print "You have not entered an email, please go back and try again";
} elseif ($name == ''){
  print "You have not entered a name, please go back and try again";
} else { 
    $send = mail($to, $subject, $body, $headers); 
    $send2 = mail($from, $subject2, $autoreply, $headers2); 
    if($send && $send2){  //<--   check both flags?
        header( "Location: http://www.thewebsite.com/thankyou.html" );
    }else{
        print "We encountered an error sending your mail, please notify mailreciepient@gmail.com";
    }
}

答案 1 :(得分:0)

您是否尝试过使用$ _POST代替$ _REQUEST?此外,任何$ fields {“fieldname”}都应为$ fields [“comment”]