What are the potential pitfalls of not properly encoding email subjects in UTF-8 when using PHP to send emails?

When email subjects are not properly encoded in UTF-8, special characters or non-English characters may not display correctly for the recipient. To ensure proper encoding, use the mb_encode_mimeheader() function in PHP to encode the email subject in UTF-8 before sending the email.

$subject = 'Subject with special characters or non-English characters';
$subject = mb_encode_mimeheader($subject, 'UTF-8');
$headers = 'Content-Type: text/plain; charset=UTF-8' . "\r\n";
mail('recipient@example.com', $subject, 'Email content', $headers);