어떤 이유로이 PHP 문이 지정된 페이지로 리디렉션되지 않습니다. 그것은 여기 나에게이 오류출력 후 PHP 리디렉션
Warning: Cannot modify header information - headers already sent by (output started at /Applications/XAMPP/xamppfiles/htdocs/srimeru/emailpage.php:203) in /Applications/XAMPP/xamppfiles/htdocs/srimeru/emailpage.php on line 229
를 제공이 섹션 내 코드입니다 :
<?php
if(!isset($_POST["submit"])){
?>
<form method="post" action="<?php echo $_SERVER["PHP_SELF"];?>">
<p>From: <input type="text" name="from"></p><br>
<p>Subject: <input type="text" name="subject"></p><br>
<p>Message: <br><textarea rows="10" cols="40" name="message"></textarea></p><br>
<input type ="submit" name="submit" value="Email">
</form>
<?php
} else {
$from = test_input($_POST["from"]);
$subject = test_input($_POST["subject"]);
$message = test_input($_POST["message"]);
$con = mysqli_connect("localhost", "root", "chendu", "SriMeru");
if (mysqli_connect_errno()){
echo "Failed to connect to Server";
}
$sql = "SELECT email FROM users";
$result = mysqli_query($con, $sql);
while ($row = mysqli_fetch_array($result)){
mail($row['email'], $subject, $message,"From: $from\n");
echo $row['email'] . $subject . $message . $from . "<br>";
}
echo"Successful Email";
header('location: http://localhost/srimeru/emailpage.php');
exit();
}
function test_input($data){
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
?>
중복 질문이있는 곳 –
기본적으로 경고는 이전에 아무 것도 출력하지 않았다면 머리말을 수정할 수 없다는 경고입니다. 'header()'를 호출하기 전에 html이나 echo를 사용할 수 없습니다. 두 번째 단락 http://php.net/manual/en/function.header.php와 첫 번째 예를 확인하십시오. –
출력 후에도 다른 페이지로 리디렉션 할 수있는 다른 방법이 있는지 알고 있습니까? –