What are the potential consequences of having HTML output before the header() function in PHP?

Having HTML output before the header() function in PHP can result in an error such as "Headers already sent" because headers must be sent before any output is sent to the browser. To solve this issue, make sure to call the header() function before any HTML output is generated in the PHP script.

<?php
// Correct way to set headers before any HTML output
header("Location: https://www.example.com");
exit;
?>