【问题标题】:PHP fails to send UTF-8 Messages [duplicate]PHP无法发送UTF-8消息[重复]
【发布时间】:2018-06-08 07:43:44
【问题描述】:

我有以下 PHP 代码:

<?php

$to      = 'info@neatgr.cf';
$subject = date("d/m/Y");
$message = 'Hey 123 !@# αβγ';

$headers  = "From: testsite < mail@testsite.com >\n";
$headers .= "Cc: testsite < mail@testsite.com >\n"; 
$headers .= "X-Sender: testsite < mail@testsite.com >\n";
$headers .= 'X-Mailer: PHP/' . phpversion();
$headers .= "X-Priority: 1\n"; // Urgent message!
$headers .= "Return-Path: mail@testsite.com\n"; // Return path for errors
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=iso-8859-1\n";

mail($to,$subject,$message,$headers);

echo "<script type='text/javascript'>alert('Message sent! We will get back to you soon!');</script>";
echo "<script>window.location.href = 'http://example.com';</script>";
?>

邮件发送正常。问题是αβγ(Unicode 字符)没有正确到达邮件收件人的一端。

这是收件人看到的:Hey 123 !@# αβγ 这是他应该看到的:Hey 123 !@# αβγ

我到处寻找并尝试了所有方法,更改标题,将我的字符串转换为 unicode 等等,但没有任何效果。也许我做错了什么?

【问题讨论】:

  • 可能是实际阅读器的问题?
  • 您使用了错误的字符集。
  • @FunkFortyNiner 我该如何解决这个问题?
  • 您说的字符编码是 IOS 8859,在您的标头中,因此邮件客户端将尝试在 8859-1 处解释您的字节
  • 使用 UTF-8 字符集

标签: php html unicode


【解决方案1】:

使用UTF-8 字符集标头,例如:

$headers .= "Content-Type: text/html; charset=iso-8859-1\n";

前往:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-08-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多