PHP联系人表单不工作
我正在尝试向我的网站添加一个联系人表单,但每次单击“发送”时,我都会看到一个黑色窗口,地址栏上显示contact.php。而且它不会重定向回。 我的网站是作为一个使用谷歌应用程序引擎的应用程序托管的 我什么都试过了,但都没用 下面是我的HTML代码:PHP联系人表单不工作,php,html,Php,Html,我正在尝试向我的网站添加一个联系人表单,但每次单击“发送”时,我都会看到一个黑色窗口,地址栏上显示contact.php。而且它不会重定向回。 我的网站是作为一个使用谷歌应用程序引擎的应用程序托管的 我什么都试过了,但都没用 下面是我的HTML代码: <form action="contact.php" method="post"> <p>Your name</p> <input type="text" name="name"/>
<form action="contact.php" method="post">
<p>Your name</p>
<input type="text" name="name"/>
<p>Your e-mail</p>
<input type="text" name="email"/>
<p>Message</p>
<textarea name="message"></textarea>
<input type="submit" value="Send"/>
<input type="reset" value="Clear"/>
</form>
<?php
$field_name = $_POST['name'];
$field_email = $_POST['email'];
$field_message = $_POST['message'];
$mail_to = 'email@here.com';
$subject = 'Message from a site visitor '.$field_name;
$body_message = 'From: '.$field_name."\n";
$body_message .= 'E-mail: '.$field_email."\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.');
window.location = 'contact.html';
</script>
<?php
}
else { ?>
<script language="javascript" type="text/javascript">
alert('Message failed.');
window.location = 'contact.html';
</script>
<?php
}
?>
你的名字
你的电子邮件
信息
下面是我的PHP代码:
<form action="contact.php" method="post">
<p>Your name</p>
<input type="text" name="name"/>
<p>Your e-mail</p>
<input type="text" name="email"/>
<p>Message</p>
<textarea name="message"></textarea>
<input type="submit" value="Send"/>
<input type="reset" value="Clear"/>
</form>
<?php
$field_name = $_POST['name'];
$field_email = $_POST['email'];
$field_message = $_POST['message'];
$mail_to = 'email@here.com';
$subject = 'Message from a site visitor '.$field_name;
$body_message = 'From: '.$field_name."\n";
$body_message .= 'E-mail: '.$field_email."\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.');
window.location = 'contact.html';
</script>
<?php
}
else { ?>
<script language="javascript" type="text/javascript">
alert('Message failed.');
window.location = 'contact.html';
</script>
<?php
}
?>
警惕(“谢谢你的留言”);
window.location='contact.html';
警报('消息失败');
window.location='contact.html';
表单中缺少结束文本区域标记。我在我的服务器上尝试了contact.php的代码,它运行正常。我同意itachi的观点,你需要打开错误报告
为什么不将contact.php设置为一个完整的页面,并完全取消重定向?您需要一个邮件服务器,php不会自行发送邮件。首先安装一个。是的,文本区域缺少关闭标记。对我来说很好。如果字段没有值,您的if-else条件将无法正常工作,但它仍会发出感谢信息。打开错误报告。您使用的是windows o linux吗?废话,对不起: