0

我想在给我发电子邮件后重定向用户。除非我在-method 之后放置一些东西(如-method)
,否则代码会运行。 有什么提示吗?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');
}
4

4 回答 4

5

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

于 2015-06-18T17:50:53.767 回答
0

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

header("Location: /myPath/thanks.html");
于 2013-04-14T17:47:37.887 回答
0
<?php
header("Location: http://www.example.com/"); /* Redirect browser */

/* Make sure that code below does not get executed when we redirect. */
exit;
?>

就我而言,有那些引号。做到了。

于 2016-09-22T19:51:37.603 回答
-1

在 header('location: ....'); 之后 你应该添加一个出口;否则脚本会一直运行直到结束。

header('Location: thanks.html');
exit;
于 2013-04-14T17:46:51.570 回答