What are the common pitfalls when formatting HTML emails using PHP and how can they be avoided?

One common pitfall when formatting HTML emails using PHP is not properly setting the Content-Type header. This can result in the email not being displayed correctly in the recipient's inbox. To avoid this issue, make sure to set the Content-Type header to "text/html" in your PHP code.

// Set the Content-Type header to ensure proper display of HTML emails
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-Type: text/html; charset=UTF-8" . "\r\n";

// Additional headers
$headers .= "From: example@example.com" . "\r\n";

// Send the email
mail($to, $subject, $message, $headers);