我正在尝试编辑PHP联系表单,因此客户可以编写特殊字符,如ščťžýá等。在我的邮件中,字符用 表示。我的PHP经验很差,请你告诉我,我做错了什么?
<?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:\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "Meno: ".clean_string($first_name)."\n";
$email_message .= "Priezvisko: ".clean_string($last_name)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "Telefon: ".clean_string($telephone)."\n";
$email_message .= "Sprava: ".clean_string($comments)."\n";
$text = iconv('utf-8', 'iso-8859-2', $text);
$headers = 'From: '.$email_from."\r\n" . "MIME-Version: 1.0\r\n" . "Content-Type: text/plain; charset=windows-1250".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);
?>