PHP形式适用于IE,但不适用于Chrome或Firefox


PHP form works in IE, but not Chrome or Firefox

好吧,相当直接的php联系表格。它在IE中提交并发送数据,并将用户带到感谢页面。但是,在谷歌浏览器和火狐中,我的用户被带到感谢页面,但他们的表单数据不会发送到电子邮件。
这是我正在使用的代码:
一页上
的表单数据

<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["姓氏"] = "姓氏" 中删除 = "姓氏" 我知道这似乎是一个愚蠢的问题,但老实说,我在这个问题上拔掉了头发。

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";
    }
}

您是否尝试过使用 $_POST 而不是 $_REQUEST?此外,任何$fields{"字段名称"}都应该$fields["注释"]