[英]PHP Contact form input doesnt support diacritics
I have small problem with my php contact form code. 我的php联络表单代码有小问题。 I have my site using diacritics which does work perfectly.
我的网站使用变音符号,效果很好。 But my contact form input after submitting looks like this "ÄÅ¡Å" after using any [0-9] keys for diacritics.
但是,使用任何[0-9]变音符号后,提交后我的联系表单输入看起来都像“ÄÅ¡Å”。
PHP file: PHP文件:
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$service = $_POST['service'];
$message = $_POST['message'];
$from = $name;
$to = 'info@email.com';
$subject = "$name - $service";
$body = "Jméno zákazníka: $name\nE-Mail zákazníka: $email\nTelefonní číslo: $phone\nservice: $service\nZpráva: $message ";
if (mail ($to, $subject, $body, $from, $headers)) {
$headers = array("Content-Type: text/html; charset=UTF-8");
} else {
echo "Failed";
}
?>
Email Output after submitting the contact form: 提交联系表格后的电子邮件输出:
First Last Name
Jméno zákazníka: Name
E-Mail zákazníka: email
Telefonní císlo: phone number
service: havárii
Zpráva: ÄÅ¡Å
the "headers" as name, email, phone, service, message is written with diacritics BUT then the input for example here: Zpráva: ÄÅ¡Å is not supported for some reason. 名称,电子邮件,电话,服务,消息等“标题”是由变音符号写的,但在此处输入例如:Zpráva:由于某种原因,不支持ÄÅ¡Å。
Also the html file include html文件也包括
<meta charset="utf-8">
UPDATE 1 更新1
Have tried to put $headers = array("Content-Type: text/html; charset=UTF-8"); 试图把$ headers = array(“ Content-Type:text / html; charset = UTF-8”); before the contact form is submitted but no change were made.
在提交联系表格之前,但未进行任何更改。 Still doesnt support any of these characters: ě š č ř ž ý á í é
仍然不支持以下任何字符:ěščřžýáíé
MORE INFO 更多信息
Adding also the html part where the problem is mostly visible 还在问题最明显的地方添加html部分
<div class="col-lg-12">
<textarea name="message" id="" cols="30" rows="10" placeholder="Zpráva">
</textarea>
</div>
You need to include your headers as the 4th param of mail()
: 您需要将标头作为
mail()
的第四个参数:
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$service = $_POST['service'];
$message = $_POST['message'];
$from = $name;
$to = 'info@email.com';
$subject = "$name - $service";
$body = "Jméno zákazníka: $name\nE-Mail zákazníka: $email\nTelefonní číslo: $phone\nservice: $service\nZpráva: $message ";
$headers = [
'Content-Type' => 'text/plain; charset=UTF-8',
'From' => $from,
];
if (mail($to, $subject, $body, $headers)) {
echo "Sent";
} else {
echo "Failed";
}
Note that this is for plain text email, not for HTML email. 请注意,这是用于纯文本电子邮件,而不是用于HTML电子邮件。
From
should be formatted as such: Name <email@example.com>
, so if you don't have information, then do not include it . From
格式应为: Name <email@example.com>
,因此,如果您没有信息,则不要包含它 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.