我有一个表单并在数据库中插入一些中文单词,没关系。表字符集是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');
}
);

答案 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">
这应该这样做,有关详细信息,请查看链接。