【发布时间】:2013-08-20 13:30:23
【问题描述】:
这是连接到contact.html页面的PHP,然后是感谢页面。我只是想要一个联系表格。它不会将文件识别为.php。我确实是这样保存的。
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$number = $_POST['number'];
$message = $_POST['message'];
$from = 'From:you';
$to = 'me@hotmail.com';
$subject = 'Hello';
$human = $_POST['human'];
$body = "From: $name\n E-Mail: $email\n Number: $number\n Message:\n $message";
if ($_POST['submit']) {
if ($name != '' && $email != '') {
if ($human == '4') {
if (mail ($to, $subject, $body, $from)) {
echo '<p>Your message has been sent!</p>';
} else {
echo '<p>Something went wrong, go back and try again!</p>';
}
} else if ($_POST['submit'] && $human != '4') {
echo '<p>You answered the anti-spam question incorrectly!</p>';
}
} else {
echo '<p>You need to fill in all required fields!!</p>';
}
header("Location: thanks.html");
}
?>
【问题讨论】:
-
标题前有回显
-
文件是
contact.html还是contact.php?应该是后者,您应该将表单操作设置为contact.php,method属性为post。此外,在使用 PHP 的header()函数之前,您不能有任何输出。这包括任何echo结构。 -
你能给我看看吗?如何做到这一点我不熟悉我仍在学习的 php。文件名为contact.html
-
@user2692442 如果您的
.html文件包含PHP 代码,那么它将不会运行,除非您告诉您的服务器将.html文件视为PHP。即:在.htaccess文件中,如果您希望.html文件作为PHP 运行,请插入AddType application/x-httpd-php .html。 -
@user2692442 创建一个名为
check_server.php的文件并将其插入并运行它,看看是否有任何东西<?php phpinfo(); ?>或<?php echo "Hello world"; ?>