09 July 2014

Chinese displayed as gibberish

To correctly display Chinese, 4 things should be done –

1. When creating the database, Chinese should be defined –

create database dbsettle character set 'gbk' collate 'gbk_chinese_ci';

use dbsettle;

2. On the web page, in the header section, Chinese should be defined –

<meta http-equiv="content-type" content="charset=gbk" />

3. In the programme code, after having connected to the database, Chinese should be defined –

mysql_select_db("dbsettle",$db);

mysql_query("set names gbk", $db);

4. In the sending email section of the code, content type should be defined –

// Always set content-type when sending HTML email

$headers = "MIME-Version: 1.0" . "\r\n";

$headers .= "Content-type:text/html;charset=gbk" . "\r\n";

// More headers

$headers .= 'From: xxxx@cicscanada.com' . "\r\n";

// $headers .= 'Cc: myboss@example.com' . "\r\n";

        // send mail

        mail($to, $subject, $message, $headers)

If all the above is done, then Chinese will correctly be displayed in the email.

No comments:

Post a Comment