Copy link to clipboard
Copied
I'm using this script to have email sent to me through a mail form:
<?php
// initialize variables for To and Subject fields
$to = 'info@testing.nl';
$subject = 'Een testmail';
$from = $_POST["from"];
$email = $_POST["email"];
$comments = $_POST["comments"];
// build message body from variables received in the POST array
$message = "Van: $from \n\n";
$message .= "Email: $email \n\n";
$message .= "Bericht: $comments";
$message = stripslashes($message);
//convert flash line breaks
$message= str_replace("\r", "\n", $message);
$message=nl2br($message);
// add additional email headers for more user-friendly reply
$additionalHeaders = "From: $from <".$email.">\r\n";
$additionalHeaders .= "Reply-To: ".$email."\r\n";
$additionalHeaders .= "MIME-Version: 1.0\r\n";
$additionalHeaders .= "Content-type: text/html; charset=utf-8\r\n";
// send email message
$OK = mail($to, $subject, $message, $additionalHeaders);
// let Flash know what the result was
if ($OK) {
echo 'sent=OK';
}
else {
echo 'sent=failed&reason='. urlencode('Er is een probleem met de server. Probeer het later nog eens.');
}
?>
The problem is that I can't get accented characters appear into the From: cc: bcc: fields. For example, when I fill the From field with 'René' it appears as 'RenX' in the From: field. I've set everything to utf-8 but that doesn't seem to matter. When I receive an html text mail, the From: fields displays accented characters as strange codes, like RenA@ or RenX for René.
In the message text itself it varies: it either displays René when the mail is viewed as plain text mail, or RenA@ when the mail is views as html text. How can I get accented characters appear inside email fields too? And also in the body text when the email is viewed as html text?
Copy link to clipboard
Copied
It comes down to this. Since flash outputs in utf-8 I used utf-8 in here too. But narrowing it down to the most basic part:
<?php
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset= UTF-8\r\n";
$headers .= "From: René <email@adres.nl>\r\n";
$OK = mail('info@testmail.nl', 'A question', 'René is my name', $headers);
if ($OK) {
echo 'sent=OK';
}
else {
echo 'sent=failed&reason='. urlencode('There is a problem with the server. Try again later.');
}
?>
When I view this through webmail I get to see RenX in the From field where it should be René. Changing charset to ISO8859-1 won't work either. I get RenX in the From field and RenA@ in the message part. And when I switch in webmail from text/html to text/plain it says Ren? in the message part.
How can I make it display René in all headers and message? Both in html mode and in plain text mode?
Copy link to clipboard
Copied
Hi
Simply setting your form to utf-8 is o/k for your OS, but this does not mean that your php server will use utf-8, try setting this using the php function "htmlspecialchars()".
See - http://www.phpwact.org/php/i18n/utf-8.
PZ