What are common pitfalls when sending HTML emails using PHP's mail function?

Common pitfalls when sending HTML emails using PHP's mail function include not setting the proper headers to indicate that the email content is HTML, not properly formatting the HTML content, and not handling errors or exceptions that may occur during the email sending process.

// Set the proper headers to indicate that the email content is HTML
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";

// Properly format the HTML content
$html_content = "<html><body><h1>Hello, world!</h1></body></html>";

// Send the email
if (mail($to, $subject, $html_content, $headers)) {
    echo "Email sent successfully";
} else {
    echo "Email sending failed";
}