0
我試圖設置我的PHP聯繫表單,當您點擊「發送」時,表示感謝並將您重定向到主頁。這是我的PHP和HTML腳本。我知道它只需要調整幾行,但不知道具體如何。我將mail.php文件上傳到我的網站目錄中。PHP聯繫表格問題(重定向)
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$call = $_POST['call'];
$website = $_POST['website'];
$priority = $_POST['priority'];
$type = $_POST['type'];
$message = $_POST['message'];
$formcontent=" From: $name \n Phone: $phone \n Call Back: $call \n Website: $website \n Priority: $priority \n Type: $type \n Message: $message";
$recipient = "[email protected]";
$subject = "Contact Form";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
if(mail($recipient, $subject, $formcontent, $mailheader))
{
header("Location: http://www.darthvixcustomsabers.com/index.html");
exit;
}
else
{
die("Error!");
}
echo "Thank You!" . " -" . "<a href='index.html' style='text-decoration:none;color:#ff0099;'> Return Home</a>";
?>
<!doctype html>
<html>
<head>
<title> DV Custom Sabers </title>
<meta charset="utf-8">
<link type="text/css" rel="stylesheet" href="style/kotorsale.css" />
<meta name="viewport" content="width=device-width" />
</head>
<div class="header"><a href="index.html">Darthvix Custom Sabers</a></div>
<div class="header1">DV Custom Sabers is the place to go for your saber needs!</div>
<div class="logo"><a href="index.html"><img src="images/logo.png" alt="schedule" height="200" width="350" border="0"></a></div>
<ul id="nav">
<li><a href="index.html">Home</a></li>
<li><a href="aboutme.html">About Me</a></li>
<li><a href="services.html">Services</a></li>
<li><a href="Gallery.html">Gallery</a></li>
<li><a href="kotorsale.html">For Sale</a></li>
<li><a href="buildlog.html">Build Log</a></li>
<li><a href="contact.html"> Contact Us</a></li>
</ul>
<div id="form">
<<form action="mail.php" method="POST">
<p>Name</p> <input type="text" name="name">
<p>Email</p> <input type="text" name="email">
<p>Priority</p>
<select name="priority" size="1">
<option value="Low">Low</option>
<option value="Normal">Normal</option>
<option value="High">High</option>
<option value="Emergency">Emergency</option>
</select>
<br />
<p>Message</p><textarea name="message" rows="6" cols="25"></textarea><br />
<input type="submit" value="Send"><input type="reset" value="Clear">
</form>
</div>
</body>
</html>
'$ recipient =「horgantm @ gmail。com
問題可能是您沒有重定向任何人。
我會編輯這樣
和頁面,在那裏你希望用戶被重定向您的代碼
編輯:
我不想我們被誤解了。
我創建了這個條件,因爲你寫了一個關於重定向的語句
…and redirects you to the home page.…
而你沒有在你的代碼中。您的問題編輯你的代碼,你卻已經忘記刪除最後一行(
echo "Thank You!" . " -" .…
),現在是useess,因爲腳本或者用戶重定向或與消息Error!
然後一個網址站參數
?successfulySent
對腳本很重要,在腳本中,您要重定向,要知道這是它應該做的事情。因此將
Location
url更改爲http://www.darthvixcustomsabers.com/index.php?successfulySent
。而我寫了
php
擴展名,是的,你需要把這個文件作爲PHP文件類型,因爲你正在放置一個PHP條件。在大多數情況下,我只會將index.html
重命名爲index.php
在哪裏放置第二個條件,簡單地說,在那裏,您希望顯示消息的位置。
來源
2013-10-16 16:25:53
所以加if(isset($ _ GET ['successfulySent'])) echo「Thank you for sendinf a message!」;到我的index.html如果我希望他們重定向到主頁,並編輯我的PHP與您列出的其他東西? – Terry
好吧我把它重定向,但我想它說,謝謝你,一旦你點擊發送,然後重定向。 – Terry
我讀過你想要重定向,但是你沒有在你的PHP代碼中添加它。 :) –