What are common issues with encoding Umlauts in PHP when sending emails through a contact form?

Common issues with encoding Umlauts in PHP when sending emails through a contact form include garbled or incorrect characters appearing in the email content. To solve this issue, you can use the mb_encode_mimeheader function to properly encode special characters like Umlauts before sending the email.

// Set the email subject with proper encoding for Umlauts
$subject = 'Subject with Umlauts: ' . mb_encode_mimeheader('Äpfel und Bären', 'UTF-8', 'Q');

// Set additional headers for proper encoding
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=UTF-8' . "\r\n";

// Send the email with encoded subject and headers
mail($to, $subject, $message, $headers);