电子邮件中缺少日语字符

时间:2013-04-22 08:41:56

标签: codeigniter email utf-8

我正在为我的项目使用codeignator框架。交付时,电子邮件中缺少一些日文字符。我检查了控制器并且所有字符都存在。我检查了配置,发送电子邮件charaset并发现它是utf-8。我还添加了这个“标题('Content-Type:text / html; charset = utf-8');” 。对于从同一项目发送的邮件也没有问题,仅针对此特定电子邮件存在问题。

公共功能电子邮件()       {

                if($this->lan == "en"){

                $site_name      = "xyz.com";
                $fromname           = "xyz.com";
                $subject            = 'sub 【'.$site_name.'】';
                $content            = " Content of email from ".$site_name."<br /><br />";
                }else{

                $site_name          = "japanesename.com";
                $fromname           = "japanesename.com";

                header('Content-Type: text/html;charset=utf-8');

                $subject            = 'japanesesub【'.$site_name.'】';
                $content            = "

                                     jp content".$site_name."<br />";
                }

        $to                 = $email;
                $this->load->library('email');
                $this->email->set_mailtype('html');
                $this->email->from($fromemail,$fromname);
                $this->email->to($to);
                $this->email->subject($subject);
                $this->email->message($content);
                $this->email->send();
                redirect('redirect_url');
}

1 个答案:

答案 0 :(得分:0)

您不需要标头,而是需要在启动其他电子邮件代码之前设置charset配置:

// Set mail config variables
$config['charset'] = 'utf-8';
$this->email->initialize($config);              

此外,您必须将任何字符串编码为UTF-8,即使您希望它们已经是utf-8编码。

$content = mb_convert_encoding($content, "UTF-8");