How can PHP scripts handle UTF-8 encoding in email subjects effectively?
PHP scripts can handle UTF-8 encoding in email subjects effectively by using the mb_encode_mimeheader function to encode the subject line in UTF-8. This function ensures that special characters are properly encoded for email headers.
$subject = 'Subject with UTF-8 characters';
$subject = mb_encode_mimeheader($subject, 'UTF-8', 'B');
$headers = 'Content-Type: text/plain; charset=UTF-8' . "\r\n";
$headers .= 'MIME-Version: 1.0' . "\r\n";
$headers .= 'From: example@example.com' . "\r\n";
mail('recipient@example.com', $subject, 'Email body', $headers);