2013-03-06 86 views
0

我想在表單成功提交後將用戶重定向到感謝頁面。我使用下面的腳本,但收到錯誤消息。請幫忙。用phpmailer發送後重定向

<?php 
session_start(); 

$name = check_input($_POST['name'], "Name cannot be empty."); 
$email  = check_input($_POST['email'], "Email address cannot be empty."); 

if(!preg_match("/^([A-Za-z\s\-]{2,45})$/i", $name)) 
{ 
show_error("name not valid."); 
} 

if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $email)) 
{ 
show_error("Email address not valid."); 
} 

htmlentities ($message, ENT_QUOTES); 

require("../PHPMailer/class.phpmailer.php"); 

$mail = new PHPMailer(); 

$mail->From  = "$email"; 
$mail->AddAddress("[email protected]"); 

$mail->Subject = "An HTML Message"; 
$mail->Body  = "Hello, <b>my friend</b>! \n\n This message uses HTML entities!"; 
$mail->WordWrap = 50; 

foreach(array_keys($_FILES['photo']['name']) as $key) { 
$source = $_FILES['photo']['tmp_name'][$key]; // location of PHP's temporary file for this. 
$filename = $_FILES['photo']['name'][$key]; // original filename from the client 

$mail->AddAttachment($source, $filename); 
} 

/* Redirect visitor to the thank you page */ 
header('Location: pthankyou.php'); 
exit(); 

function check_input($data, $problem='') 
{ 
$data = trim($data); 
$data = stripslashes($data); 
$data = htmlentities($data); 
if ($problem && strlen($data) == 0) 
{ 
    show_error($problem); 
} 
return $data; 
} 

function show_error($Error) 
{} 
?> 

錯誤消息

警告:無法修改標題信息 - 已經 發送報頭(輸出開始的PHPMailer/class.phpmailer.php:1370)在process.php 上線66

+0

什麼是第66行,這不是完整的腳本是嗎? – 2013-03-06 08:47:18

+0

66行有這個腳本。 header('Location:pthankyou.php'); exit();這被偶然遺漏了。 – 2013-03-07 03:31:48

回答

0

redirect()是一個特殊的php內置函數,需要在之前調用之前的任何輸出。

輸出可能是:

  • 在你的代碼呼應
  • html標籤

然而

  • VAR傾銷
  • spacese前<?php標籤,在這裏,我dind't看到redirect()調用,所以如果你想要更好的幫助,你必須包括代碼片段,其中問題是