Reputation: 5157
I'm using the following mail script but the problem is that it converts some characters. A typical mail looks like this:
Neue Nachricht von Mustermann, Max ([email protected]):
Hallo Herr Platzhalter, wie soeben besprochen, würden wir gern ein
"Schild" mit der Aufschrift "Aufschrift" bei Ihnen
bestellen. Bitte teilen Sie uns doch mit, wie wir da
verfahren müssen ... Ihnen einen schönen
Urlaub! Familie Mustermann
I'd guess that this ($message = filter_var($_POST['message'], FILTER_SANITIZE_SPECIAL_CHARS);) messes it up. So how do I change that without making it unsecure? And are there other improvements I should add to that script?
<?php
//Enter your email here
$your_email = "mymail";
//Enter the subject of the mail here
$subject = "Kontakt Webseite";
$name = $_POST['name'];
$email = $_POST['email'];
//Filter HTML characters
$message = filter_var($_POST['message'], FILTER_SANITIZE_SPECIAL_CHARS);
$error = "Fehler: ";
//Default message if unsuccessful and no other reason found
$return_message = $error."Leider hat das Versenden der Nachricht nicht geklappt, bitte schreiben Sie mir direkt an ".$your_email." eine E-Mail";
if(strlen($name) > 0 && strlen($email) > 0 && strlen($message) > 0) {
if(filter_var(filter_var($email, FILTER_VALIDATE_EMAIL), FILTER_SANITIZE_EMAIL)) {
try {
$body = "Neue Nachricht von ".$name." (".$email."):\n".$message;
$header = "From: ".$email;
mail($your_email, $subject, $body, $header);
$return_message = "Die Nachricht wurde erfolgreich versendet, ich melde mich schnellst möglich bei Ihnen";
}
catch(Exception $e) { }
} else {
$return_message = $error."Ihre E-Mail Adresse scheint ungültig zu sein.";
}
} else {
$return_message = $error."Ein oder mehrere Felder waren nicht ausgefüllt.";
}
echo $return_message;
?>
Upvotes: 0
Views: 589
Reputation: 1591
Slokun makes a valid point. Additionally, as the emails content contains HTML entities and appears to be in another language, it would be a good idea to append the following to the email header to ensure correct rendering by receiving email clients:
Replace:
$header = "From: ".$email;
With:
$header = "From: " . $email . "\r\n";
$header .= "Content-type: text/html; charset=utf-8" . "\r\n";
Edit: Having said that, if you include the above lines in your script you won't need to remove the line that sanitizes HTML entities. Your problem at the moment is that receiving email clients are not interpreting the emails content as HTML but pure text.
Upvotes: 1
Reputation: 4033
The only thing it would really be doing is trying to make sure the receiving client could handle it properly, and there's never any guarantee of that anyhow :P
In this case, it's turning your special characters into HTML entities (\n
-> 

, for example), which would break your emails without a fair amount of work to fix them up again. Get rid of the filter and you should be good.
Upvotes: 0