用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-zs-]{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("myfriend@example.net");
$mail->Subject  = "An HTML Message";
$mail->Body     = "Hello, <b>my friend</b>! nn 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)第66行

redirect()是一个特殊的php内置函数,需要在任何输出之前调用

输出可以是:

  • html标记
  • var倾销
  • <?php标签前的空格

但是,我没有看到你的代码中包含redirect()。如果您需要更具体的帮助,您必须包含您的问题所在的代码片段。

最新更新