php代码中的标头重定向不起作用

spa*_*mup 0 php http-redirect http-headers

我想通过电子邮件发送给我后重定向用户.
代码运行,除非我在email()-method 之后放了一些东西(比如header()-method).
任何提示?

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');
}
Run Code Online (Sandbox Code Playgroud)

小智 5

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