由于某种原因,这个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;
}
?>
答案 0 :(得分:0)
您必须删除echo"Successful Email";
语句才能使位置标头正常工作。