【问题标题】:Pound sign is displayed as '」' symbol in sent email, have header meta tag as charset=utf-8磅符号在发送的电子邮件中显示为“」”符号,标题元标记为 charset=utf-8
【发布时间】:2023-03-21 20:59:01
【问题描述】:

通过电子邮件发送时,我的 php 文件中的井号符号被转换为奇怪的“」”符号。

我尝试了许多不同的解决方案,但似乎都没有。

已尝试将 '£' 替换为 &pound 等...

这是在我的标题中:

<meta http-equiv="content-type" content="text/html; charset=utf-8" />
$message .= "Price Each: £".$row_get['price']. "\n";  
mail($to1, $subject1, $message, $header1); // send the e-mail to customer

提前致谢

【问题讨论】:

标签: php html


【解决方案1】:

问题是编码问题。您没有看到 UTF-8 渲染。

£ 符号被编码为 0xA3,但在 MS932 encoding ("Japanese ANSI") 中,0xA3 是您看到的“」”符号。

要正确设置电子邮件的编码,您需要添加

$headers = 'Content-Type: text/html; charset=utf-8' . "\r\n";

到你的标题。

您还应该仔细检查您的文件是否以 UTF-8 正确编码。如果你用 MS932 编码写井号,那将被编码为 65410 65379。巧合的是,」是相同的 '」' 符号(ツ」 将显示 ツ」)。

如果您想了解更多信息,Jon Skeet 在this SO answer 中对此进行了更彻底的解释(Java,但根本原因是相同的)。

【讨论】:

    【解决方案2】:

    这样做

    $header1  = 'MIME-Version: 1.0' . "\r\n";
    $header1 .= 'Content-type: text/html; charset=utf-8' . "\r\n";
    mail($to1, $subject1, $message, $header1);
    

    【讨论】:

    • 也试过了,但不开心。
    • 刚刚发现,生成的电子邮件在 PC 上正确显示,而其唯一的 Apple Mac 显示错误。
    • 我怀疑 Apple 'Mail' 编码有问题!
    猜你喜欢
    • 1970-01-01
    • 2023-03-25
    • 1970-01-01
    • 2014-01-01
    • 2015-10-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-17
    相关资源
    最近更新 更多