用phpmailer发送后重定向
问题描述:
我想在表单成功提交后将用户重定向到感谢页面。我使用下面的脚本,但收到错误消息。请帮忙。用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
答
VAR倾销 spacese前
redirect()
是一个特殊的php内置函数,需要在之前调用之前的任何输出。
的输出可能是:
- 在你的代码呼应
- html标签
然而
<?php
标签,在这里,我dind't看到redirect()
调用,所以如果你想要更好的帮助,你必须包括代码片段,其中问题是
什么是第66行,这不是完整的脚本是吗? – 2013-03-06 08:47:18
66行有这个脚本。 header('Location:pthankyou.php'); exit();这被偶然遗漏了。 – 2013-03-07 03:31:48