Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/268.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
php代码中的头重定向赢得';行不通_Php_Http Headers_Http Redirect - Fatal编程技术网

php代码中的头重定向赢得';行不通

php代码中的头重定向赢得';行不通,php,http-headers,http-redirect,Php,Http Headers,Http Redirect,我想在给我发电子邮件后重定向用户。 除非我在email()-方法(如header()-方法)后面添加了内容,否则代码将运行。 有什么提示吗 function process() { $msg = "Form Contents: \n\n"; foreach($this->fields as $key => $field) $msg .= "$key : $field \n"; $to = 'mymail@gmail.com'; $s

我想在给我发电子邮件后重定向用户。
除非我在
email()
-方法(如
header()
-方法)后面添加了内容,否则代码将运行。
有什么提示吗

function process()
{
    $msg = "Form Contents: \n\n";
    foreach($this->fields as $key => $field)
        $msg .= "$key :  $field \n";

    $to = 'mymail@gmail.com';
    $subject = 'thesubject';
    $from = $this->fields['email'];

    mail($to, $subject, $msg, "From: $from\r\nReply-To: $from\r\nReturn-Path: $from\r\n");

    header('Location: thanks.html');
}
标题后('位置:…');您应该添加一个出口;否则,脚本将一直运行到结束

header('Location: thanks.html');
exit;
标题后('位置:…');您应该添加一个出口;否则,脚本将一直运行到结束

header('Location: thanks.html');
exit;

你的位置应该是绝对的,而不是相对的

header("Location: /myPath/thanks.html");

你的位置应该是绝对的,而不是相对的

header("Location: /myPath/thanks.html");

当我遇到类似的问题时,它通常是一行末尾缺少分号,或者像这里的情况一样,缺少括号,因为
foreach
code块应该被{}阻塞。看

当我遇到类似的问题时,通常是一行末尾缺少分号,或者像这里的情况一样,缺少括号,因为
foreach
代码块应该被{}阻塞。看


在我的例子中,有那些引用的标志。就是这样。



在我的例子中,有那些引用的标志。就是这样。

你会得到什么错误?我曾经得到过PHP解析错误:语法错误、意外的“header”(T_字符串)、D:\xampp\htdocs\process\u form.PHP中D:\xampp\PHP\logs\PHP_error_log中的预期函数(T_function)(T_function)发送电子邮件时没有任何错误吗?如果您尝试使用@mail(…)?$this->fields应该是$field,对吗$from=$field['email'];是的,电子邮件已经发送了。但是之后的重定向没有。你会得到什么错误?我曾经得到PHP解析错误:语法错误,意外的“头”(T_字符串),D:\xampp\htdocs\process\u form.PHP中的预期函数(T_函数),在D:\xampp\PHP\logs\PHP\u error\u日志中发送电子邮件时没有任何错误吗?如果您尝试使用@mail(…)?$this->fields应该是$field,对吗$from=$field['email'];是的,电子邮件已经发送了。但之后的重定向不会。无论如何,您都应该添加出口;)您仍然应该添加出口;)