Are there any best practices for ensuring HTML formatting is preserved in emails sent via PHP?

When sending HTML emails via PHP, it's important to ensure that the formatting is preserved. One common issue is that the HTML code may get stripped or rendered incorrectly by the email client. To prevent this, you can use the PHP `mail()` function along with the headers to specify the content type as HTML.

$to = "recipient@example.com";
$subject = "HTML Email Test";
$message = "<html><body><h1>Hello, World!</h1><p>This is a test email.</p></body></html>";

$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";

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