What are the necessary header information adjustments needed to send HTML emails with the mail() function in PHP?

When sending HTML emails using the mail() function in PHP, it is important to include the necessary header information to ensure that the email is properly formatted and displayed as HTML content. This includes setting the Content-Type header to "text/html" and optionally setting the charset to ensure proper encoding. Failure to include these headers may result in the email being displayed as plain text or not formatted correctly.

$to = "recipient@example.com";
$subject = "HTML Email Test";

$message = "<html><body><h1>Hello, this is a test HTML email!</h1></body></html>";
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";

mail($to, $subject, $message, $headers);