What are common issues with sending emails with PHP mail() function, particularly related to encoding and special characters like umlauts?

When sending emails with PHP's mail() function, one common issue is related to encoding special characters like umlauts. To solve this problem, you can set the email headers to specify the content type and character encoding as UTF-8.

$to = "recipient@example.com";
$subject = "Subject with ümläuts";
$message = "Message with ümläuts";
$headers = "From: sender@example.com\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=UTF-8\r\n";

mail($to, $subject, $message, $headers);