警告:无法修改标头信息 - 已经发送的标头([重复]

This question already has an answer here:

I want to pass a variable to a page, but cannot modify header... is always in the way

if(isset($_POST['send']))
{
$sender = $_SESSION['Email'];
$receiver = $_POST['email'];
$message = $_POST['textmessages'];
$date = date("Y-m-d h:i:sa");

$q = 'INSERT INTO `tblmessage`(`id`,`sender_name`,`receiver_name`,`message_text`,`date_time`,`userid`)
       VALUES("","'.$sender.'","'.$receiver.'","'.$message.'","'.$date.'","'.$user_id.'")';
$r = mysqli_query($con, $q);

if($r)
{
          header("location.href='messages.php?user=".$receiver);
}   
else
{
    echo $q;
}

}

I tried passing the user to the page, but:

output started at C:\xampp\htdocs\MBPH(Beta)\messages.php:79) in `C:\xampp\htdocs\MBPH(Beta) ewmessage.php on line 38

always pops up, that line 38 is

'header("location.href='messages.php?user=".$receiver);'
</div>

You could add ob_end_flush() before your header() function. It will clear out the current output buffer and your header() should be sent.

Reference: ob_end_flush() documentation

You can try this code

ob_start();
Your output here
ob_get_contents();