运行我的脚本时,我收到几个这样的错误:
警告:不能更改头信息-头已经发出(输出开始/some/file.php:12)在/some/file.php上线23
错误消息中提到的行包含header()和setcookie()调用.
这可能是什么原因?以及如何解决它?
我正在使用 PHP,我收到了这条消息
无法修改标头信息 - 标头已由(输出开始于
执行如下代码后:
<?php
if (condition) {
if (condition) {
//Statement
}
$to = $_POST['email'];
$subject = "Registration Confirmation";
$message = '
<html>
<head>
<title>'.$subject.'</title>
</head>
</html>
';
// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
// More headers
$headers .= 'From: <contact@ghanalifestore.com>' . "\r\n";
mail($to,$subject,$message,$headers);
header('Location: reset.php?username='.$username);
exit();
}else {
//statement
}
Run Code Online (Sandbox Code Playgroud)
根据Stackoverflow 的这个答案,我认为错误来自变量中的 HTML 代码$message。我真的不知道如何修改该变量的内容以避免错误。
请帮我解决这个问题。