How can the headers of the email be configured to ensure proper display of UTF-8 data in PHP?
To ensure proper display of UTF-8 data in PHP email headers, the headers should be configured to include the appropriate content type and charset. This can be achieved by setting the "Content-Type" header to "text/html; charset=UTF-8" and using the mb_encode_mimeheader function to encode any non-ASCII characters in the header values.
// Set email headers
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type: text/html; charset=UTF-8" . "\r\n";
$headers .= "From: sender@example.com" . "\r\n";
// Encode any non-ASCII characters in the header values
$subject = 'Subject with non-ASCII characters';
$encoded_subject = mb_encode_mimeheader($subject, 'UTF-8');
// Send email with configured headers
mail('recipient@example.com', $encoded_subject, 'Email content', $headers);
Related questions
-
GD functions rotated rectangles complex shapes
-
temporary file content storage FTP upload
-
Kohana constants methods