How can the charset and encoding be properly set in the header of a PHP email to ensure correct display of special characters like umlauts?
Special characters like umlauts can be displayed correctly in PHP emails by setting the charset and encoding properly in the email header. This can be achieved by using the `Content-Type` header with the charset specified as `UTF-8`. Additionally, the `Content-Transfer-Encoding` header should be set to `quoted-printable` to ensure proper encoding of special characters.
<?php
$to = "recipient@example.com";
$subject = "Subject with Umlauts: äöü";
$message = "Message with Umlauts: äöü";
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type: text/html; charset=UTF-8" . "\r\n";
$headers .= "Content-Transfer-Encoding: quoted-printable" . "\r\n";
mail($to, $subject, $message, $headers);
?>
Keywords
Related Questions
- How can one ensure proper authentication and authorization when accessing files on a web server from a local machine using PHP?
- What are potential pitfalls when filtering out Bouncemails based on Betreffzeilen like "failure" or "Returned mail" in PHP?
- What are some best practices for automating email sending in PHP?