为什么忽略header()函数——我的方法的结果


why ignores the header() function the result of my method?

$result = $mail->send($recipient, $headers, $html);
    if($result === 1)
    {
        $report= "1";
        header("Location: objednavka.php?reaction=".$report);
      //echo("Your message has been sent!");
    }
    else
    {
        $report= "2";
        header("Location: objednavka.php?reaction=".$report);
      //echo("Your message was not sent: " . $result);
    }

如果此邮件函数运行失败,则if语句决定它是否成功。如果我使用echo((部分,它会写下你的消息已经发送。但如果我想将用户重定向到另一个页面,它就不起作用。为什么?如何成功调用标头函数?

来自PHP-header((:

请记住,在发送任何实际输出之前,必须调用header((,无论是通过普通HTML标记、文件中的空行还是从PHP发送

您忘记设置相应的状态代码(header()(

header("Location: objednavka.php?reaction=$report", true, 301);