我在 PHP HTML 表单中遇到了一个非常烦人的特殊字符问题,一切都是 UTF-8,但特殊字符仍然显示为问号......
这是我当前的 PHP 代码,我希望你们中的一个人会注意到这个问题......
<?php
header('Content-Type: text/html; charset=utf-8');
iconv_set_encoding("internal_encoding", "utf-8");
if(isset($_POST['fyrirtaeki'])) {
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "hafsteinn@tikktakk.is";
$email_subject = "SKILAGREIN";
function died($error) {
// your error code can go here
echo "We are very sorry, but there were error(s) found with the form you submitted. ";
echo "These errors appear below.<br /><br />";
echo $error."<br /><br />";
echo "Please go back and fix these errors.<br /><br />";
die();
}
// validation expected data exists
if(!isset($_POST['fyrirtaeki']) ||
!isset($_POST['kennitala']) ||
!isset($_POST['heimilisfang']) ||
!isset($_POST['laun-1']) ||
!isset($_POST['kenn-1']) ||
!isset($_POST['timabil-1']) ||
!isset($_POST['afdregid-1']) ||
!isset($_POST['sum']) ||
!isset($_POST['dags']) ||
!isset($_POST['simi'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$fyrirtaeki = $_POST['fyrirtaeki'];
$kennitala = $_POST['kennitala'];
$netfang = "medlag@medlag.is";
$heimilisfang = $_POST['heimilisfang'];
$simi = $_POST['simi'];
$dags = $_POST['dags'];
$sum = $_POST['sum'];
$laun1 = $_POST['laun-1'];
$kenn1 = $_POST['kenn-1'];
$timabil1 = $_POST['timabil-1'];
$afdregid1 = $_POST['afdregid-1'];
$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
$email_message = "Upplýsingar má finna hér að neðan.\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "Fyrirtæki: ".clean_string($fyrirtaeki)."\n";
$email_message .= "Kennitala: ".clean_string($kennitala)."\n";
$email_message .= "Heimilisfang: ".clean_string($heimilisfang)."\n";
$email_message .= "Sími: ".clean_string($simi)."\n\n\n";
if ($laun1 != "") {
$email_message .= "Nafn launþega: ".clean_string($laun1)."\n";
$email_message .= "Kennitala: ".clean_string($kenn1)."\n";
$email_message .= "Launatímabil: ".clean_string($timabil1)."\n";
$email_message .= "Afdregid: ".clean_string($afdregid1)."\n\n";
}
$email_message .= "Skilagrein greidd dags:".clean_string($dags)."\n";
$email_message .= "Samtals: ".clean_string($sum)."\n\n\n\n";
// create email headers
$headers = 'From: '.$netfang."\r\n".
'Reply-To: '.$netfang."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);
?>
<!-- include your own success html here -->
Takk fyrir, eyðublað móttekið.
<?php
}
?>