0

我的联系表格中有以下 PHP。

// Ensure a message was entered, then sanitize it
if(!empty($_POST['cf_m']) && $_POST['cf_m']!='Enter Your Message Here')
{
    $message = strip_tags($_POST['cf_m']);
}

当我通过电子邮件收到消息时,挪威字符 æ、ø、å 变为 æ、ø、Ã¥。

我该怎么做才能显示正确的字符?

4

5 回答 5

6

看来您的表单是作为UTF-8,但电子邮件是作为ISO-8859-1(或其他变体)发送的。您可能希望通过设置标头来显式设置已发送电子邮件的字符编码Content-type,例如:

Content-type: text/plain; charset=UTF-8

设置$additional_headersPHPmail()函数的参数以完成此操作。

于 2009-08-27T12:34:41.383 回答
1

您必须在邮件标头中设置编码,就像在 mail() ( http://de.php.net/manual/de/function.mail.php ) 的 php-comments 中解释的那样:

<?php
function mail_utf8($to, $subject = '(No subject)', $message = '', $from) {
  $header = 'MIME-Version: 1.0' . "\n" . 'Content-type: text/plain; charset=UTF-8'
    . "\n" . 'From: Yourname <' . $from . ">\n";
  mail($to, '=?UTF-8?B?'.base64_encode($subject).'?=', $message, $header);
}
?>
于 2009-08-27T12:33:42.743 回答
0

我认为这些字符是 UTF8 编码的,所以你可以使用utf8_decode 函数来正确显示它们

于 2009-08-27T12:35:06.080 回答
0

在整个代码中使用 UTF-8。对我来说,这个页面非常有帮助。

于 2009-08-27T13:01:17.210 回答
0

这是关于发送带有挪威字符的电子邮件吗?
看看SwiftMailer,它是一个很棒的处理电子邮件的库。http://swiftmailer.org/docs/message-charset中描述了设置消息的字符集。(而且由于 utf-8 是 SwiftMailer 的默认值,你不必在你的情况下做任何事情。)

于 2009-08-27T14:05:01.203 回答