php重定向不起作用-我正在使用header()
我有一个提交表单的php文件。我输入index.html,然后它将信息发送到email.php。提交表单后,我试图重定向回index.html,但收到错误:“警告:无法修改标题信息-标题已由发送” 我尝试过使用php重定向不起作用-我正在使用header(),php,html,redirect,Php,Html,Redirect,我有一个提交表单的php文件。我输入index.html,然后它将信息发送到email.php。提交表单后,我试图重定向回index.html,但收到错误:“警告:无法修改标题信息-标题已由发送” 我尝试过使用标题(“位置:http://www.mywebpage.com/index.html");在php文件的每一行,它都不起作用。下面是我的代码。有什么想法吗 <?php $filename = "email.csv"; $exists = (file_exists($filename
标题(“位置:http://www.mywebpage.com/index.html");代码>在php文件的每一行,它都不起作用。下面是我的代码。有什么想法吗
<?php
$filename = "email.csv";
$exists = (file_exists($filename));
$handle = fopen($filename, 'a');
$msg = "Thank you for your appointment.\n";//EMail message
$stringToAdd=""; //File into
if (!$exists){
foreach($_POST as $name => $value) {
$stringToAdd.="$name,";
}
$stringToAdd.="\n";
$new=False;
fwrite($handle, $stringToAdd);
}
$stringToAdd="";
foreach($_POST as $name => $value) {
print "$name : $value<br>";
$msg .="$name : $value\n";
$stringToAdd.="$value,";
}
$stringToAdd.="\n";
fwrite($handle, $stringToAdd);
//now close the file
fclose($handle);
$to = $_POST["uniqname"]."@tobey.com";
$headers = "From: ". "UMSI CDO" ."<umsi.careers@tobey.com>\r\n";
mail($to, 'Appointment Scheduled', $msg, $headers); // 'Appointment Scheduled' is the subject
echo "Email sent";
?>
去掉php结束标记?>
和php开始标记前的空格、html、空行您需要删除此打印“$name:$value
”代码>,因为在调用header()
之前您无法输出任何内容。我知道,我仔细检查了这个问题,并试图实现他们所说的内容,但仍然没有成功。除了最后一行之外,我看不到有输出到浏览器的内容……文件开头有空格吗?了解其余的错误会很有帮助。它会输出我所有的表单数据,然后打印发送的电子邮件。我希望它这样做,然后重定向到一个新页面我知道以前有人问过它,在问我的问题之前,我倒了一遍stackoverflow问题……但我仍然认为有些地方不对劲,因为根据我放置header()调用的位置,我要么会收到错误,要么它会正确发送电子邮件并忽略header()呼叫completely@kegewe:去掉php结束标记?>
和php开始标记@kegewe:你成功了吗?是的,我把它放在$stringToAdd=”“后面的第18行代码>删除结束标记后,它终于开始工作。
header("Location:http://www.mywebpage.com/index.html");