我是PHP的新手。我一直在网站上使用这个例子并且重定向到感谢页面不起作用,任何人都可以解决原因吗?此外,我也没有收到自己的电子邮件,我有以下示例代码:http://form.guide/email-form/html-email-form.html
下载完整代码后,它只是重定向到PHP代码而不是转到感谢页面。
if( empty($errors))
{
$to = $myemail;
$email_subject = "Contact form submission: $firstname";
$email_body = "You have received a new message. ".
" Here are the details:\n Name: $firstname \n Email: $email_address \n Message \n $message";
$headers = "From: $myemail\n";
$headers .= "Reply-To: $email_address";
mail($to,$email_subject,$email_body,$headers);
//redirect to the 'thank you' page
header('Location: contact-form-thank-you.html');
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Contact form handler</title>
</head>
<body>
<!-- This page is displayed only if there is some error -->
<?php
echo nl2br($errors);
?>
</body>
</html>
你忘了:
<?php
在代码的第一行。 Php解释器不知道你的代码在哪里开始,你看到PHP代码为html。