mistery_girl mistery_girl - 1 year ago 72
PHP Question

How to output Chinese in HTML file

I have a form and insert some chinese words in database and it's ok. Table charset is UTF8. Problem appears when I select this data and send it via mail as HTML attachment.
Then, Chinese doesn't display properly. How to fix charset before send data via mail? Should I use some headers and will it work?

My code looks like that:

//$attachedBodyContent is data from database that contains some chinese words
function($message) use ($data, $template, $subject, $attachedBodyContent) {
$message->to($data['email'], $data['name'])


Answer Source

When you generate .html attach file you should include in your <head>

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

In this case you can use this code for merge your content with <head>

    $header = '<!DOCTYPE html>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    $footer = '</body>
    $allContent = $header.$attachedBodyContent.$footer;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download