What are common issues when sending emails with HTML and plain text content in PHP?

One common issue when sending emails with HTML and plain text content in PHP is that some email clients may not properly display the HTML content, leading to a poor user experience. To solve this issue, you can include both HTML and plain text versions of the email content in the email headers.

// Set the email headers to include both HTML and plain text content
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers .= "From: example@example.com" . "\r\n";
$headers .= "Content-type: text/plain; charset=iso-8859-1" . "\r\n";

// Send the email
$to = "recipient@example.com";
$subject = "Test Email";
$message_html = "<html><body><h1>Hello, World!</h1></body></html>";
$message_plain = "Hello, World!";
mail($to, $subject, $message_html, $headers, "-f example@example.com");