我的简单HTML联系表单发送的重音字符存在问题。当我收到一封电子邮件时,其中包含一些重音字符(ľ,š,č,ť,ž,ý,á,í,é,ú,ä,ô,......),这是不可读的。我认为这是非常常见的问题,但我仍然无法实现已经回答我的PHP的解决方案。
我已经将utf-8的元标记设置为HTML的<head>
,我也尝试将标题输入到PHP文件中,但老实说,我并不确定它应该放在哪里。
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
以下是我的表格代码:
<form name="contactForm" method="POST" action="mail_sender.php">
<div class="row">
<!--NAME-->
<div class="control-group col-md-6 col-sm-6">
<label class="control-label" for="inputName">MENO<sup>*</sup></label>
<div class="controls">
<input class="form-control" name="name" type="text" placeholder="meno">
</div>
</div>
</div>
<div class="row">
<!--EMAIL-->
<div class="control-group col-md-6 col-sm-6">
<label class="control-label" for="inputEmail">EMAIL<sup>*</sup></label>
<div class="controls">
<input name="email" type="text" class="form-control col-md-4 col-sm-4" placeholder="email">
</div>
</div>
</div>
<div id='contactForm_errorloc'></div>
<div class="row">
<!--PHONE-->
<div class="control-group col-md-6 col-sm-6">
<label class="control-label" for="inputEmail">TELEFÓN<sup>*</sup></label>
<div class="controls">
<input name="phone" type="text" class="form-control col-md-4 col-sm-4" placeholder="telefónne číslo">
</div>
</div>
</div>
<div class="row">
<!--MESSAGE-->
<div class="control-group col-md-12 col-sm-12">
<label for="textarea" class="control-label">SPRÁVA<sup>*</sup></label>
<div class="controls">
<textarea class="form-control" name="message" rows="4" id="textarea"></textarea>
</div>
</div>
</div>
<div id='contactForm_errorloc'></div>
<div class="control-group form-button-offset">
<input style="margin-top: 10px;" type="submit" class="btn btn-default" value="Poslať správu" />
</div>
</form>
这是我的PHP文件的代码:
<?php
$errors = '';
$myemail = 'email@domain.com';//<-----Put Your email address here.
if(empty($_POST['name']) ||
empty($_POST['email']) ||
empty($_POST['phone']) ||
empty($_POST['message']))
{
$errors .= "\n Error: all fields are required";
}
$name = $_POST['name'];
$email_address = $_POST['email'];
$phone = $_POST['phone'];
$message = $_POST['message'];
if (!preg_match(
"/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i",
$email_address))
{
$errors .= "\n Error: Invalid email address";
}
if( empty($errors))
{
$to = $myemail;
$email_subject = "Contact form submission: $name";
$email_body = "You have received a new message. ".
" Here are the details:\n Name: $name \n Email: $email_address \n Phone: $phone \n Message \n $message";
$headers = "From: $myemail\n";
$headers .= "Reply-To: $email_address";
mail($to,$email_subject,$email_body,$headers);
//redirect to the 'thank you' page
header('Location: contact-form-thank-you.html');
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Contact form handler</title>
</head>
<body>
<!-- This page is displayed only if there is some error -->
<?php
echo nl2br($errors);
?>
</body>
</html>
我尝试了很多东西,但没有成功。感谢您的时间,我将非常感谢您的回答。