How can PHP developers ensure compliance with RFC standards, such as RFC 2047, when sending emails with non-ASCII characters like umlauts using PHP?
When sending emails with non-ASCII characters like umlauts using PHP, developers can ensure compliance with RFC standards, such as RFC 2047, by encoding the subject and body of the email using the base64 encoding method. This ensures that the characters are properly represented in the email headers and content.
$subject = 'Subject with non-ASCII characters like ümläuts';
$subject = '=?UTF-8?B?' . base64_encode($subject) . '?=';
$body = 'Body with non-ASCII characters like ümläuts';
$body = '=?UTF-8?B?' . base64_encode($body) . '?=';
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/plain; charset=UTF-8' . "\r\n";
$headers .= 'From: sender@example.com' . "\r\n";
// Send email
mail('recipient@example.com', $subject, $body, $headers);
Keywords
Related Questions
- How can PHP handle form submissions with multiple select boxes that have the same name?
- What role does server time synchronization play in determining the expiration of PHP cookies set by the server?
- In PHP, what are some strategies for displaying a preview of an uploaded image and confirming its correct appearance before processing it further?