What role does UTF-8 encoding play in ensuring proper display of special characters like umlauts in email subjects when using PHP for sending emails?

When sending emails with special characters like umlauts in the subject using PHP, it's important to use UTF-8 encoding to ensure proper display across different email clients. This encoding allows for the correct representation of special characters in the email subject line, avoiding any garbled or incorrectly displayed characters.

// Set the email subject with UTF-8 encoding
$subject = 'Subject with special characters like ümläüts';
$subject = '=?UTF-8?B?' . base64_encode($subject) . '?=';

// Send the email with the properly encoded subject
mail('recipient@example.com', $subject, 'Email content', 'From: sender@example.com');