挪威人物

时间:2009-08-27 12:30:48

标签: php character

我的联系表格中有以下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']);
}

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

为了显示正确的字符,我该怎么办?

5 个答案:

答案 0 :(得分:6)

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

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

设置PHP mail() function$additional_headers参数以完成此操作。

答案 1 :(得分:1)

您必须在邮件标题中设置编码,就像在mail-comments(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);
}
?>

答案 2 :(得分:0)

我认为这些字符是UTF8编码的,因此您可以使用utf8_decode function来正确显示它们

答案 3 :(得分:0)

在整个代码中使用UTF-8。对我来说,this page非常有用。

答案 4 :(得分:0)

这是关于发送带有挪威字符的电子邮件? 看一下SwiftMailer,这是一个很棒的图书馆来处理电子邮件。 http://swiftmailer.org/docs/message-charset描述了设置消息的字符集。 (因为utf-8是SwiftMailer的默认设置,所以你不需要做任何事情。)