Are there specific functions or methods in PHP that can help ensure proper encoding of variables to avoid display issues with Umlauts in email headers?

To ensure proper encoding of variables to avoid display issues with Umlauts in email headers, you can use the PHP `mb_encode_mimeheader()` function. This function will properly encode the string for MIME header fields, including Umlauts, to ensure correct display in email headers.

$subject = "Äpfel und Birnen";
$encoded_subject = mb_encode_mimeheader($subject, 'UTF-8');

// Usage example in sending email
$headers = "From: sender@example.com\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/plain; charset=UTF-8\r\n";
$headers .= "Subject: $encoded_subject\r\n";

mail('recipient@example.com', 'Subject', 'Message', $headers);