我试图重定向到谢谢!成功验证表单信息并生成电子邮件后的页面。但标题功能不起作用/页面不重定向,我得到了我的404。我的代码如下:
<?php
/* Set e-mail recipient */
$myemail = "myemail@myemail.com";
$subject = "Visitor Message";
/* Check all form inputs using check_input function */
$firstname = check_input($_POST['firstname'], "Enter your first name");
$lastname = check_input($_POST['lastname'], "Enter your last name");
$email = check_input($_POST['emailaddress']);
$message = check_input($_POST['message'], "Write your message");
/* If e-mail is not valid show error message */
if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $email))
{
show_error("E-mail address not valid");
}
/*Prepare the message for the e-mail */
$emailmessage = "Hello!
Your have received a message!
Name: $firstname $lastname
E-mail: $email
Message:
$message
End of message
";
/* Send the message using mail() function */
mail($myemail, $subject, $emailmessage);
/* Redirect visitor to the thank you page */
header('Location: http://www.mywebsite.com/thanks.html');
exit();
/* Functions we used */
function check_input($data, $problem='')
{
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
if ($problem && strlen($data) == 0)
{
show_error($problem);
}
return $data;
}
function show_error($myError)
{
?>
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="tsd_main.css">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>TSD</title>
</head>
<body>
<div class="header">
<img src="twosundawnbanner.png" id="banner">
<ul>
<li><a href="index.hmtl">Home</a></li>
<!-- <li><a href="#news">News</a></li>
-->
<li><a href="#services">Services</a></li>
<li><a href="#projects">Projects</a></li>
<li><a href="#giving">Giving</a></li>
<li><a href="about.html">About</a></li>
<li><a href="#contact">Contact</a></li>
<li style="float:right"><a class="active" href="#shop">Shop</a></li>
</ul>
</div>
<div class="maincontent">
<b>Please correct the following error:</b><br />
<?php echo $myError; ?>
</div>
<div class="footer">
TSD © 2017
</div>
</body>
</html>
<?php
exit();
}
?>
答案 0 :(得分:-1)
如果您可以分享一步一步的截图,那么最好先了解一下,并尝试查看错误日志以了解错误的真正原因