我是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>
答案 0 :(得分:0)
您忘记了:
<?php
在代码的第一行。 php解释器不会弄清楚您的代码从哪里开始,您会看到php代码为html。