I'm using the following code to send an e-mail:
<?php
$to = $_POST['email'];
$subject = "Subject!";
$message = "Hello!";
$headers = "From: Me<example@example.com>\r\n";
$headers .= "Return-Path: example@example.com\r\n";
$headers .= "BCC: example@example.com\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/plain; charset=utf-8\r\n";
mail($to,$subject,$message,$headers);
?>
Although using charset=utf-8
the characters in the subject and the email address line still doesn't get decoded right. I'm getting characters like this: ößä
.
How can I set the charset for subject and email address line, too?
To encode the subject of an email you should use:
And then inside the
mail
function: