2009-08-27 58 views
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']); 
} 

当我收到通过电子邮件,挪威字符,A,O消息和AE变成了¥A,Ã|

我能以显示正确的字符呢?

+0

我已经与这个问题斗争过了。如果你想了解更多关于发生了什么的信息,请阅读:http://forthescience.org/blog/2008/02/29/unraveling-unicode-problems-in-wikkawik​​i/ – 2009-08-27 13:03:18

回答

1

必须设置编码的邮件标题,像它在邮件()的PHP-评论(http://de.php.net/manual/de/function.mail.php)真实解释说:

<?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); 
} 
?> 
6

看来你的形式担任UTF-8,但E-邮件发送为ISO-8859-1(或其他品种)。您可能希望通过设置Content-type头,例如明确设置发送的电子邮件的字符编码:

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

设置PHP mail() function$additional_headers参数来实现这一目标。

0

这是关于发送电子邮件与挪威字符?
看看SwiftMailer,这是一个伟大的图书馆处理电子邮件。设置消息的字符集在http://swiftmailer.org/docs/message-charset中描述。 (因为UTF-8是SwiftMailer的默认设置,所以你不必为你的情况做任何事情。)

相关问题