How can HTML content be properly formatted in email messages sent through PHP?

When sending HTML content in email messages through PHP, it is important to set the appropriate headers to ensure proper formatting. This can be done by including the "Content-Type" header with the value "text/html" in the mail function. Additionally, make sure that the HTML content is properly formatted with inline styles or a linked stylesheet to ensure consistent rendering across different email clients.

$to = 'recipient@example.com';
$subject = 'HTML Email Test';
$message = '<html><body><h1>Hello, World!</h1><p>This is a test email with HTML content.</p></body></html>';
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

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