For some reason this php statement is not redirecting to the specified page. It gives me this error
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
Here is my code for this section:
<?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;
    }
?>
 
     
    