0
我正在尝试重定向到谢谢!成功验证表单信息并生成电子邮件后,即可生成页面。但标题功能不起作用/页面不重定向,我得到我的404代替。我下面的代码给出:标题()函数重定向?
<?php
/* Set e-mail recipient */
$myemail = "[email protected]";
$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();
}
?>
的真正原因,如果您收到404错误,重定向正在工作。猜测在http:// www.mywebsite.com/thanks.html中没有实际的页面,它正在被重定向到。确保文件的域和位置是正确的。否则会有一个'.htaccess'规则或其他条件被应用到它,从而阻止了所需的结果。请参阅:https://stackoverflow.com/a/768472/1144627 – fyrye
谢谢!你指出我正确的方向! –