我在网页上有一个php表单,它将邮件发送到我指定的某个地址。如果我在gmail, hotmail或任何在线邮件服务中查看邮件,一切都很好。变音符没有问题,你可以看到šđžćč
很好。
但是,如果我把一个邮件地址配置为进入我的outlook,任何变音符号将显示为一些奇怪的符号ĹžÄĹĄĹžÄ
。
我甚至试过将邮件从gmail转发到我的Outlook地址,同样的事情发生了!我甚至将Outlook中的字符编码设置为UTF-8
,在我的表单中也是如此。
这是一些奇怪的故障在Outlook或我做了什么错误的形式?
任何帮助都是感激的。
编辑:我有一个表单在我的html:
<?php
//If the form is submitted
if(isset($_POST['submit'])) {
//Check to make sure that the name field is not empty
if(trim($_POST['contactname']) == '') {
$hasError = true;
} else {
$name = trim($_POST['contactname']);
}
//Check to make sure that the subject field is not empty
if(trim($_POST['subject']) == '') {
$hasError = true;
} else {
$subject = trim($_POST['subject']);
}
if(trim($_POST['goaddress']) == '') {
$hasError = true;
} else {
$goaddress = trim($_POST['goaddress']);
}
if(trim($_POST['toaddress']) == '') {
$hasError = true;
} else {
$toaddress = trim($_POST['toaddress']);
}
if(trim($_POST['date']) == '') {
$hasError = true;
} else {
$date = trim($_POST['date']);
}
if(trim($_POST['time']) == '') {
$hasError = true;
} else {
$time = trim($_POST['time']);
}
//Check to make sure sure that a valid email address is submitted
if(trim($_POST['email']) == '') {
$hasError = true;
} else if (!eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+'.[A-Z]{2,4}$", trim($_POST['email']))) {
$hasError = true;
} else {
$email = trim($_POST['email']);
}
//If there is no error, send the email
if(!isset($hasError)) {
$emailTo = 'random.mail@gmail.com'; //Put your own email address here
$body = "Ime i prezime: $name 'n'nEmail: $email 'n'nTelefon: $subject 'n'nPolazišna adresa: $goaddress 'n'nOdredišna adresa: $toaddress 'n'nDatum: $date 'n'nVrijeme: $time";
$headers = 'From: RANDOM NAME <'.$emailTo.'>' . "'r'n" . 'Reply-To: ' . $email;
mail($emailTo, $subject, $body, $headers);
$emailSent = true;
}
}
?>
我有一个单独的。php文件叫做form .php,我在每个页面(下拉表单)上调用我的html,它有以下元素:
<div class="float-form">
<div class="slideToggler2" style="float;left; z-index: 100;position: absolute; cursor:pointer;">
<img style="pointer:cursor;" src="../images/naruci_en.png" />
</div>
<div class="slideContent2" style="display:none; z-index: 10;position: absolute;top:20px; ">
<div class="wrapp">
<div id="contactWrapper_en" role="form" >
<?php if(isset($hasError)) { //If errors are found ?>
<p class="error">Please check if you have filled out all the fields, and try again. Thank you.</p>
<?php } ?>
<?php if(isset($emailSent) && $emailSent == true) { //If email is sent ?>
<div class="success">
<p><strong>Email sent successfully!</strong></p>
<p>One of our agents will contact you in a little while.</p>
</div>
<?php } ?>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" id="contactform">
<div class="stage clear">
<label for="name"><strong>Full name: <em>*</em></strong></label>
<input type="text" name="contactname" id="contactname" value="" class="required" role="input" aria-required="true" />
</div>
<div class="stage clear">
<label for="email"><strong>Email: <em>*</em></strong></label>
<input type="text" name="email" id="email" value="" class="required email" role="input" aria-required="true" />
</div>
<div class="stage clear">
<label for="subject"><strong>Telephone: <em>*</em></strong></label>
<input type="text" name="subject" id="subject" value="" class="required" role="input" aria-required="true" />
</div>
<div class="stage clear">
<label for="goaddress"><strong>Starting address: <em>*</em></strong></label>
<input type="text" name="goaddress" id="goaddress" value="" class="required" role="input" aria-required="true" />
</div>
<div class="stage clear">
<label for="toaddress"><strong>Destination: <em>*</em></strong></label>
<input type="text" name="toaddress" id="toaddress" value="" class="required" role="input" aria-required="true" />
</div>
<div class="stage clear">
<label for="date"><strong>Date of departure: <em>*</em></strong></label>
<input type="text" name="date" id="date" value="" class="required" role="input" aria-required="true" />
</div>
<div class="stage clear">
<label for="time"><strong>Time of departure: <em>*</em></strong></label>
<input type="text" name="time" id="time" value="" class="required" role="input" aria-required="true" />
</div>
<p class="requiredNote"><em>*</em> Required</p>
<input type="submit" value="Send Message" name="submit" id="submitButton_en" title="Send the order!" />
</form>
</div>
</div>
</div>
</div>
还有一个验证jquery注册表单…
您不需要设置字符编码或担心MIME在电子邮件正文中的想法。这是自找麻烦的。
通过使用Swiftmailer之类的东西来修复它,它允许您简单轻松地构建MIME块。正确设置字符编码应该可以解决大部分问题。