我的联系表格php
每次都会在提交时下载文件,不知道为什么会发生这种情况,但我的代码是正确的,并且已经在其他网站上使用过这个代码,它工作正常。
这是我的HTML
:
<form id="ContactForm" action="contact.php" method="post">
<div>
<div class="wrapper">
<div class="bg">
<input class="input" type="text" name="name" id="name" value="" tabindex="1">
</div>
Name: </div>
<div class="wrapper">
<div class="bg">
<input class="input" type="text" name="email" id="email" value="" tabindex="1">
</div>
Email: </div>
<div class="wrapper">
<div class="bg2">
<textarea cols="1" rows="1" name="message" id="message"></textarea>
</div>
Message: </div>
<input type="submit" value="Submit" class="button" /> </div>
</form>
这是PHP
:
<?php
$field_name = $_POST['name'];
$field_email = $_POST['email'];
$field_message = $_POST['message'];
$mail_to = 'email address';
$subject = 'Message from a website visitor '.$field_name;
$body_message = 'From: '.$field_name."\n\n";
$body_message .= 'E-mail: '.$field_email."\n\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.');
window.location = 'contact.html';
</script>
<?php
}
?>
请注意:我是故意把邮箱地址拿出来的$mail_to
以前有人遇到过这个问题并设法找出它是什么吗?