ÅÄÖ从表格发送时出错了

时间:2017-07-07 09:46:53

标签: php character-encoding

我试图从瑞典ÅÄÖåäö的表格中获取我的邮件,但邮件中出错了。任何人? 服务器设置为UTF8 我的标题是:

<?php header('Content-Type: text/html; charset=iso-8859-1'); ?>
<html>
<head>
<title>xxxxxx</title>
</head>
<body bgcolor="#CCCCCC">
<table align="center" border="0">
<tr><td>
</html>

我的mail.inc.php编码如下:

<?php header("Content-Type: text/html; charset=iso-8859-1");
function mail_file($to, $from, $subject, $body, $file) {
$boundary = md5(rand());
$headers = array(
    'MIME-Version: 1.0',
    //"Content-Type: multipart/mixed; charset=iso-8859-1; boundary=\"{$boundary}\"", - 170707
    "Content-Type: multipart/mixed; boundary=\"{$boundary}\"",
    "From: {$from}"
);
$message = array(
    "--{$boundary}",
    'Content-Type: text/HTML; charset=iso-8859-1',
    'Content-Transfer-Encoding: quoted-printable', 
    '', 
    quoted_printable_encode($body),         '',                            
    "--{$boundary}",
    "Content-Type: {$file['type']}; name=\"{$file['name']}\"",
    "Content-Disposition: attachment; filename=\"{$file['name']}\"",
    "Content-Transfer-Encoding: base64", 
    '',
    chunk_split(base64_encode(file_get_contents($file['tmp_name']))),
    "--{$boundary}--",
    '',
);
mail($to, $subject, implode("\r\n", $message), implode("\r\n", $headers));
}
?>

这让我疯了。请帮忙

1 个答案:

答案 0 :(得分:0)

我不知道它是否是存档的最佳方式 在你的mail()函数$subject之前尝试这个

$subject = '=?UTF-8?B?'.base64_encode($subject).'?=';

然后发送邮件

mail($to, $subject, implode("\r\n", $message), implode("\r\n", $headers));

OR

mail($to, '=?UTF-8?B?'.base64_encode($subject).'?=', implode("\r\n", $message), implode("\r\n", $headers));