Welcome Guest, Not a member yet? Register   Sign In
Japanese (multi-byte) characters & email library

[eluser]Aaron L.[/eluser]
Hello, In my controller (encoded in UTF-8) I am attempting to send an email which contains Japanese (multibyte) characters. The body of the email comes out fine, but the subject line are just garbled characters. Any ideas/tips/hints/thoughts as to what might be going on here?

This has been a headache of mine for a long time....

The standard for Japanese emails is iso-2022-jp, not utf-8 - it would be best to change your email encoding and run the subject and body text through iconv(). This will solve most, but not all, mojibake problems.

For example:

$config['charset'] = 'iso-2022-jp';


$this->email->to('[email protected]');
$this->email->from('[email protected]');
$this->email->subject(iconv('utf-8', 'iso-2022-jp', $subject));
$this->email->message(iconv('utf-8', 'iso-2022-jp', $message));
iso-2022-jp is a 7-bit encoding as opposed to 8-bit, so often plays nicer with email clients across the board. Even Hotmail, notorious for destroying utf-8 encoded emails.

[eluser]Aaron L.[/eluser]
Thanks for your reply! I will try your suggestions and let you know what happens. Thanks!

[eluser]Aaron L.[/eluser]
Hello again, I tried using your code and unfortunately the subject line still comes out as jibberish. My partner and I tried it in a couple of different mail clients and still no luck. Any other thoughts/ideas?


Yeah... like I said, it might work... ;-)

Okay... check the Content-Tranfer-Encoding of your received emails... are they 7bit or 8bit? It should be 7bit. CI seems to set the encoding by default to 8-bit (understandable as UTF-8 is the default), which might be causing the mojibake, so you'll have to hack the email core to set the encoding to 7bit.

It might be possible to use
$config['_encoding'] = '7bit';

but I've never tried it personally... I'm only dealing with Japanese and English speakers so I just hardcoded the 7bit into the header.


This is code for send mail in Japanese language.


        $subject = 'パスワードお知らせ';
        $message = 'パスワード再発行。';
        $name = "管理者";
        $name=mb_convert_encoding($name,'iso-2022-jp', 'SHIFT-JIS');
        $subject=mb_convert_encoding($subject,'iso-2022-jp', 'SHIFT-JIS');
        $this->email->to('[email protected]');
        $this->email->from('[email protected]',$name);

[quote author="座頭市" date="1186673766"]
$this->email->subject(iconv('utf-8', 'iso-2022-jp', $subject));
$this->email->message(iconv('utf-8', 'iso-2022-jp', $message));

I think the problem is that iconv is including 'Subject:', so it's included for a second time when sending the email. I used str_replace to remove inconv's 'Subject:' and it worked fine.

Theme © iAndrew 2016 - Forum software by © MyBB