Why are HTML entities not being displayed correctly in the email content sent using PHP's mail() function?

When using PHP's mail() function to send emails, HTML entities may not be displayed correctly because the email content is treated as plain text by default. To ensure that HTML entities are displayed properly in the email, you need to set the appropriate headers to indicate that the content is HTML formatted.

$to = 'recipient@example.com';
$subject = 'HTML Entities Test';
$message = '<html><body><Hello World></body></html>';
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";

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