【发布时间】:2011-10-23 10:23:05
【问题描述】:
下面的代码应通过将数据发送到相关数据库表的联系表单生成 UTF-8 编码的电子邮件。但是,它仍然无法正确显示 UTF-8 字符。你能看看我是否输入错误/没有添加/弄乱下面的代码吗?非常感谢!
<?php
$text = "Results from form:\n\n";
$space = ' ';
$line = '
';
foreach ($_POST as $key => $value)
{
if ($req == '1')
{
if ($value == '')
{echo "$key is empty";die;}
}
$j = strlen($key);
if ($j >= 20)
{echo "Name of form element $key cannot be longer than 20 characters";die;}
$j = 20 - $j;
for ($i = 1; $i <= $j; $i++)
{$space .= ' ';}
$value = str_replace('\n', "$line", $value);
$conc = "{$key}:$space{$value}$line";
$text .= $conc;
$space = ' ';
}
mail($emailadd, $subject, $text, 'From: '.$emailadd.'');
echo '<META HTTP-EQUIV=Refresh charset=utf-8 CONTENT="0; URL='.$url.'">';
?>
编辑:
感谢克里斯的快速响应——不过,我们的电子邮件表单依赖于“func.php”文件,其中包含网站的各种设置。目前'sendemail'代码如下:
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers .= "From: ".$hostmail." \r\n";
$headers .= "Reply-To : ".$hostmail." \r\n";
return mail($to, $subj, $body, $headers);
我试过改变如下,没有成功...有什么想法吗?
$headers .= "From: ".$hostmail." \r\n";
$headers .= "Reply-To : ".$hostmail." \r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/plain; charset=utf-8\r\n";
$headers .="Content-Transfer-Encoding: 8bit";
$body=htmlspecialchars_decode($body,ENT_QUOTES);
return mail($to, "=?utf-8?B?".base64_encode($subj)."?=",$body, $headers);
【问题讨论】:
标签: forms utf-8 character-encoding