2013-10-11 77 views
2

這裏是我的代碼:提交PHP電子郵件表單後,如何重定向到HTML頁面?

<?php 
$name = $_POST['name']; 
$email = $_POST['email']; 
$subject = $_POST['subject']; 
$message = $_POST['message']; 
$formcontent = "From: $name \n Email: $email \n Subject: $subject \n Message: $message"; 
$recipient = "[email protected]"; 
$subject = "Contact Form"; 
$mailheader = "From: $email \r\n"; 
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!"); 
?> 

我只需要知道如何點擊提交,並確保通過腳本發送電子郵件後重定向到一個HTML頁面。任何幫助將不勝感激!

回答

2

一下添加到腳本的末尾:

header("Location: URL"); 

其中URL是要重定向頁面的URL。

+0

我試過一樣,它說警告:不能修改標題信息 - 標題已發送 –

+1

請參閱https://stackoverflow.com/questions/8028957/how-to-fix-headers-already-sent-error-in -php – Barmar

0

PHP

header('Location: login.php?msg=1'); 

的JavaScript

<script> window.location='forgot.php'</script>"; 

HTML

<META HTTP-EQUIV="REFRESH" CONTENT="3;URL=http://google.com"> 
0

你可能缺少開放的形式和關閉形式,或者你只是包括它

<form name="PL" action="newForm.php" method="post"> 
<?php 
$name = $_POST['name']; 
$email = $_POST['email']; 

$subject = $_POST['subject']; 

$message = $_POST['message']; 

$formcontent = "From: $name \n Email: $email \n Subject: $subject \n Message: 
$message"; 

$recipient = "[email protected]"; 

$subject = "Contact Form"; 

$mailheader = "From: $email \r\n"; 

mail($recipient, $subject, $formcontent, $mailheader) or die("Error!"); 
include "newForm2.php"; 
?> 
<input type="submit" name="btn_submit" value="Display Invoice" /> 
</form> 
+0

爲使mail()函數正常工作,您的php.ini文件需要正確的SMTP設置。這也取決於你是否通過POP3或IMAP發送。 – KarlosFontana

相關問題