我正在尝试创建一个将发送到我的电子邮件的表单。该表单在Firefox中完美运行,但在Chrome / Internet Explorer 中无效。希望有人可以提供帮助!
编辑发生的事情是我的php只是在浏览器中显示为文本 EDIT
HTML CODE:
<form action="contact.php" method="post" id="contactform">
<label for="myName">Name: </label>
<input type="text" name="myName" id="myName" />
<label for="myEmail">E-mail: </label>
<input type="email" name="myEmail" id="myEmail" />
<label for="myNumber">Phone Number: </label>
<input type="tel" name="myNumber" id="myNumber" />
<label for="myComments">Comments: </label>
<textarea name="myComments" id="myComments" rows="2" cols="20"></textarea>
<input id="mySubmit" type="submit" value="Submit">
</form>
PHP:
<?php
$field_name = $_POST['myName'];
$field_email = $_POST['myEmail'];
$field_phone = $_POST['myNumber'];
$field_message = $_POST['myComments'];
$mail_to = 'alexandriadrugs@yahoo.com';
$subject = 'Message from '.$field_name;
$body_message = 'From: '.$field_name."\n";
$body_message .= 'E-mail: '.$field_email."\n";
$body_message .= 'Phone: '.$field_phone."\n";
$body_message .= 'Message: '.$field_message;
$headers = 'From: '.$field_email."\r\n";
$headers .= 'Reply-To: '.$field_email."\r\n";
$mail_status = mail($mail_to, $subject, $body_message, $headers);
if ($mail_status) { ?>
<script language="javascript" type="text/javascript">
alert('Thank you for the message. We will contact you shortly.');
window.location = 'contact.html';
</script>
<?php
}
else { ?>
<script language="javascript" type="text/javascript">
alert('Message failed. Please, send an email to alexandriadrugs@yahoo.com');
window.location = 'contact.html';
</script>
<?php
}
?>`
答案 0 :(得分:1)
Firefox将从文件目录运行Php,而IE和Chrome会将它们显示为纯文本,除非您明确要求它们以HTTP协议运行该文件。这似乎是一个错误,但实际上,通过遵循要求的正确协议,它们实际上比Firfox做得更好:
打开文件: 文件:/// C:/xampp/htdocs/mypage.php
请求网页 http:// localhost / mypage.php
答案 1 :(得分:0)
我很确定你没有运行支持PHP的网络服务器。 PHP代码不会被识别出来,它会像它的html一样显示。
答案 2 :(得分:0)
http://
localhost 你应该解决你的问题