Im trying to edit PHP contact form, so the customers can write special characters like ščťžýá etc. In my mail, the characters are represented with �. My PHP experience is very poor, can you please tell me, what did I do wrong?
<?php
if(isset($_POST['email'])) {
$email_to = "my mail";
$email_subject = "Sprava z formularu";
function died($error) {
echo "Formular nebol odoslany.";
echo "Vyskytli sa tieto chyby:<br /><br />";
echo $error."<br /><br />";
echo "Vratte sa a opravte tieto chyby.<br /><br />";
die();
}
if(!isset($_POST['first_name']) ||
!isset($_POST['last_name']) ||
!isset($_POST['email']) ||
!isset($_POST['telephone']) ||
!isset($_POST['comments'])) {
died('Vyskytol sa problem s vasim formularom.');
}
$first_name = $_POST['first_name']; // required
$last_name = $_POST['last_name']; // required
$email_from = $_POST['email']; // required
$telephone = $_POST['telephone']; // not required
$comments = $_POST['comments']; // required
$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$email_from)) {
$error_message .= 'Adresa, ktoru ste zadali je neplatna.<br />';
}
$string_exp = "/^[A-Za-z .'-]+$/";
if(strlen($first_name) < 2) {
$error_message .= 'Meno, ktore ste zadali je neplatne.<br />';
}
if(strlen($last_name) < 2) {
$error_message .= 'Priezvisko, ktore ste zadali je neplatne.<br />';
}
if(strlen($comments) < 2) {
$error_message .= 'Sprava, ktoru ste zadali je neplatna.<br />';
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = "Udaje z formulara:
";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "Meno: ".clean_string($first_name)."
";
$email_message .= "Priezvisko: ".clean_string($last_name)."
";
$email_message .= "Email: ".clean_string($email_from)."
";
$email_message .= "Telefon: ".clean_string($telephone)."
";
$email_message .= "Sprava: ".clean_string($comments)."
";
$text = iconv('utf-8', 'iso-8859-2', $text);
$headers = 'From: '.$email_from."
" . "MIME-Version: 1.0
" . "Content-Type: text/plain; charset=windows-1250".
'Reply-To: '.$email_from."
" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);
?>