我在网页上有一个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;
}
}
?>
我有一个名为forma.php的单独的.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注册表单......
答案 0 :(得分:0)
您永远不会设置字符编码或担心MIME在该电子邮件正文中的想法。这是灾难的秘诀。
使用Swiftmailer之类的东西来修复它,它允许您简单轻松地构建MIME块。正确地setting the character encoding应该解决大部分问题。