2017-07-20 112 views
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 &copy; 2017 
</div> 
</body> 
</html> 
<?php 
exit(); 
} 
?> 
+0

的真正原因,如果您收到404錯誤,重定向正在工作。猜測在http:// www.mywebsite.com/thanks.html中沒有實際的頁面,它正在被重定向到。確保文件的域和位置是正確的。否則會有一個'.htaccess'規則或其他條件被應用到它,從而阻止了所需的結果。請參閱:https://stackoverflow.com/a/768472/1144627 – fyrye

+0

謝謝!你指出我正確的方向! –

回答

-1

如果你可以只共享一步步截圖將更好地理解並嘗試尋找在錯誤日誌,瞭解錯誤