What are the risks of using the mail() function in PHP without adhering to RFC standards, especially when dealing with special characters in emails?

When using the mail() function in PHP without adhering to RFC standards, there is a risk of emails not being delivered properly or being flagged as spam due to special characters not being encoded correctly. To solve this issue, it is important to properly encode special characters in email headers using the mb_encode_mimeheader() function in PHP.

$subject = 'Subject with special characters: é, ñ, ü';
$subject = mb_encode_mimeheader($subject, 'UTF-8', 'Q');

$headers = 'From: sender@example.com' . "\r\n" .
           'Reply-To: sender@example.com' . "\r\n" .
           'MIME-Version: 1.0' . "\r\n" .
           'Content-type: text/html; charset=utf-8' . "\r\n";

mail('recipient@example.com', $subject, 'Email content', $headers);