PHP Mail:Firefox 和 IE 中的特殊字符显示不同
我在使用 PHP 邮件功能通过电子邮件发送表单时遇到问题。这是我正在使用的代码:
$name = $_POST['name'];
$last_name = $_POST['last_name'];
$company = $_POST['company'];
$email = $_POST['email'];
$country = $_POST['country'];
$phone = $_POST['phone'];
$message = $_POST['message']); //This comes from the form
$formcontent="Name: $name $last_name <br> Company: $company <br> Email: $email <br> Country: $country <br> Telephone: $phone <br><br> Message: $message";
$mailheader = 'MIME-Version: 1.0' . "\r\n";
$mailheader .= 'Content-type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable' . "\r\n";
$mailheader .= 'From: ' . $email . "\r\n";
mail("[email protected]", "subject", $formcontent, $mailheader) or die("Error!");
这是一种将发送西班牙语和特殊字符的表单,例如 ñ、重音符号、ç 等...
问题是,如果我像这样使用它,它可以正常工作Firefox 3.6.3,但是当在 Internet Explorer 8 中使用表单时,发送的特殊字符全都乱了(比如用 ¡ 而不是 ç)。但是,如果我将 utf8_encode 添加到 $formcontent 中的变量中,那么它在 IE 中可以工作,但在 Firefox 中停止工作,显示诸如 η 而不是 ç 之类的内容。
无论浏览器如何,我该怎么做才能使其正常工作?任何帮助将不胜感激!
编辑:
我注意到,如果我在使用邮件发送之前回显$formcontent变量,如果我使用的是Firefox,特殊字符已经搞乱了。如何避免浏览器干扰正在发送的内容?拜托我现在真的一无所知!!!我不知道要改变什么才能让某些东西发挥作用。即使它是一个简化版本,是否有其他选择可以让 PHP Mail 在两个浏览器中使用特殊字符?
I have a problem when sending a form via email using the PHP Mail function. This is the code that I'm using:
$name = $_POST['name'];
$last_name = $_POST['last_name'];
$company = $_POST['company'];
$email = $_POST['email'];
$country = $_POST['country'];
$phone = $_POST['phone'];
$message = $_POST['message']); //This comes from the form
$formcontent="Name: $name $last_name <br> Company: $company <br> Email: $email <br> Country: $country <br> Telephone: $phone <br><br> Message: $message";
$mailheader = 'MIME-Version: 1.0' . "\r\n";
$mailheader .= 'Content-type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable' . "\r\n";
$mailheader .= 'From: ' . $email . "\r\n";
mail("[email protected]", "subject", $formcontent, $mailheader) or die("Error!");
This is a form that will be sending spanish and special characters, like ñ, accents, ç, etc...
The problem is that, if I use it like this, it works fine in Firefox 3.6.3, but when using the form in Internet Explorer 8, the special characters that sends are all messed up (like ç instead of a ç). However, if I add utf8_encode to the variables in the $formcontent, then it works in IE, but it stops working in Firefox, showing stuff like η instead of ç.
What can I do to make it work regardless of the browser? Any help would be much appreciated!
EDIT:
I've noticed that, if I echo the $formcontent variable before sending it with mail, if I'm using Firefox, the special characters are already messed-up. How can I avoid the browsers interfering with what's being sent? Please I'm totally clueless right now!!! I don't know what to change to have something working. Even if it's a dumbed down version, is there any alternative to have PHP Mail working with special characters in both browsers?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
基本上,您需要确保页面上的每个字符集都是相同的。确保页面也有 utf-8 字符集。由于您以 utf8 格式发送,因此输入也必须来自 utf8。
您能否向我们展示发送邮件的页面(或现场演示)的代码?
Basically you need to make sure that every charset on your page is the same. Make sure the page has a utf-8 charset aswel. Since you're sending it in utf8 the input must come from utf8 aswell.
Could you perhaps show us the code of the page (or a live demo) where the mail is being made?