我从html表单中获取一些数据,并用PHP通过电子邮件发送它们。问题是我得到了奇怪的字符,因为用户在表单中输入的语言是捷克语。
例如,名称Anežka变为Anežka
这是我的php的代码,用于发送电子邮件。
<?php
if(isset($_POST['submit'])){
$to_alex = "myemail@honeywell.com"; // this is your Email address
$first_name = $_POST['fname'];
$first_name=mb_convert_encoding($first_name, "UTF-8", "ISO-8859-1");
$last_name = $_POST['lname'];
$email = $_POST['email'];
$skola = $_POST['vysoka_skola'];
$obor = $_POST['obor'];
$prace = $_POST['prace'];
$phone_num=$_POST['phone_number'];
$linkedin=$_POST['linkedin'];
$oponenta=$_POST['oponenta'];
$vedouciho=$_POST['vedouciho'];
$files = $_FILES['myfile']['name'];
$kategorie = $_POST['kategorie'];
//echo gettype($files);
$all_thesis_string="";
$all_vedouciho_string="";
for($index=0;$index<count($_FILES['myfile']['name']);$index++){
$all_thesis_string.=$_FILES['myfile']['name'][$index].","; //create a string with all bachelor attachments of user
}
for($index=0;$index<count($_FILES['vedouciho_files']['name']);$index++){
$all_vedouciho_string.=$_FILES['vedouciho_files']['name'][$index].","; //create a string with all vedouciho attachments of user
}
for($index=0;$index<count($_FILES['oponenta_files']['name']);$index++){
$all_vedouciho_string.=$_FILES['oponenta_files']['name'][$index].","; //create a string with all oponenta attachments of user
}
$subject = "Form submission of ".$first_name." ".$last_name;
$message = "User Details: \n\n Jméno: $first_name \n Příjmení: $last_name \n Email: $email \n Telefon: $phone_num \n Linkedin: $linkedin \n Vysoká škola: $skola \n Studijní obor: $obor \n Odkaz na bakalářskou práci: $prace \n Kategorie: $kategorie \n Posudek oponenta: \n $oponenta \n Posudek vedouciho: \n $vedouciho \n Bakalářská práce: $all_thesis_string \n Vedouciho files: $all_vedouciho_string";
$headers = "From:" . $first_name;
mail($to_alex,$subject,$message,$headers);
echo '<span style="color:#AFA;text-align:center;"><strong>"Přihláška úspěšně odeslána. Děkuji "</strong></span>';
//include 'upload.php';
// You can also use header('Location: thank_you.php'); to redirect to another page.
}
?>我在最后一次尝试中尝试了mb_convert_encoding,但仍然有问题。
发布于 2021-07-26 19:57:44
您需要在程序的输入和输出阶段处理可能出现的问题:
<head>中的某个地方使用标记<meta charset="utf-8">。否则,在将表单数据发回给您时,它可能会回退到某些传统编码。Mime版本: 1.0内容类型:文本/纯文本;字符集=utf-8内容传输编码: quoted-printable
https://stackoverflow.com/questions/68529271
复制相似问题