如何在HTML文件中输出中文

时间:2016-07-16 17:04:18

标签: php encoding

我有一个表单并在数据库中插入一些中文单词,没关系。表字符集是UTF8。当我选择此数据并通过邮件将其作为HTML附件发送时,会出现问题。 然后,中文没有正确显示。如何通过邮件发送数据之前修复charset?我应该使用一些标题吗?它会起作用吗?

我的代码看起来像这样:



//$attachedBodyContent is data from database that contains some chinese words
Mail::send(
            "emails.applicationTemplate",
            $data,
            function($message) use ($data, $template, $subject, $attachedBodyContent) {
                $message->to($data['email'], $data['name'])
                    ->from($template['from'],$template['from_name'])
                    ->subject($subject)
                    ->attachData($attachedBodyContent,'YourApplicationData.html');
              
            }
        );




2 个答案:

答案 0 :(得分:2)

生成.html附加文件时,应包含在<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

在这种情况下,您可以使用此代码将您的内容与<head>

合并
<?php
    $header = '<!DOCTYPE html>
    <html>
    <head>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    </head>
    <body>';
    $footer = '</body>
    </html>';
    $allContent = $header.$attachedBodyContent.$footer;
?>

答案 1 :(得分:1)

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

这应该这样做,有关详细信息,请查看链接。

http://www.inventpartners.com/chinese-chars