不显示 UTF-8 西班牙语字符



我拼命地试图让西班牙语字符在我发送的MIME电子邮件中正确显示。

因此,经过几个小时的搜索,我尝试了以下方法,但没有成功。

  1. 将以下内容添加到我的 PHP 中:

    mb_internal_encoding("UTF-8");
    header('Content-Type: text/html; charset=utf-8');
    
  2. 确保我的文件在记事本++中是UTF8

  3. 在我的 HTML 代码中添加了以下内容:

    <meta http-equiv='Content-Type' content='text/html; charset=UTF-8'>
    
  4. 将以下内容添加到我的 my.cnf 文件中并重新启动服务器:

    init-connect='SET NAMES utf8'
    
  5. 已确保所有表都处于utf8_unicode_ci

  6. 在选择查询之前向查询添加了以下内容:

    SET NAMES utf8;
    
  7. 我正在使用 mime 发送带有以下代码的电子邮件:

    // Creating the Mime message
    $mime = new Mail_mime($crlf);
    // Setting the body of the email
    $mime->setTXTBody($body);
    $mime->setHTMLBody($html);
    $headers = array ('From' => $from, 'To' => $to,
                    'Subject' => $subject, 
                    "Content-Type: text/html;charset=utf-8");
    $smtp = Mail::factory('smtp',
    array ('host' => $host,
        'port' => $port,
        'auth' => true,
        'username' => $username,
        'password' => $password));
    $body = $mime->get();
    $headers = $mime->headers($headers);
    $recipients = $to.", ".$bcc;
    $mail = $smtp->send($recipients , $headers, $body);
    

我希望有人能为我指出正确的方向。

不要使用自己的解决方案来撰写和发送电子邮件,您可能会出错。使用一些电子邮件类,例如PHPMailer。刚刚设置了字符集属性:

$mailer = new PHPMailer();
$mailer->CharSet = 'utf-8';

或邮件

根据文档,您可以传递head_charset、text_charset和html_charset参数。传递给 $mime->headers() 的内容类型标头可能被覆盖。

问题很简单:使用西班牙语时 UTF-8 很糟糕,您必须使用 8859-15。

UTF-8主要用于英语,即使英语使用Julious Ceasar和罗马帝国规定的拉丁数字和字母,创作者也不关心拉丁语言(真的很有趣),并声称它是国际HTML5准备和所有废话。

也许创作者的世界仅限于美国,这就是他们对世界的全部了解。但是外面的世界更大更好,我希望他们明白这一点,一个新的 UTF-9 推出......

甚至HTML5验证者也认为:

Legacy encoding iso-8859-15 used. Documents should use UTF-8.

现在,如果您想在超级专业的国际标准UTF-8中使用西班牙语,则必须执行以下操作:

像这样对每个符号进行编码,否则它将不起作用:

á -> &aacute;
é -> &eacute;
í -> &iacute;
ó -> &oacute;
ú -> &uacute;
ñ -> &ntilde;

谁创建了 UTF-8?

我想

通了。 这是哑剧电子邮件的问题。

    // Creating the Mime message
    $mime = new Mail_mime($crlf);
    // Setting the body of the email
    $mime->setTXTBody($body);
    $mime->setHTMLBody($html);
    $mimeparams=array(); 
    $mime->addAttachment($filename,'application/pdf');
    //set SMTP server details - Using keys from www.protectedtrust.com 
    $port = "25";
    $host = "in.mailjet.com";
    $username = "fcb0ee027e8cc30b1a47caf9c6272db1";
    $password = "fe80add357c21cae0133632c4c25177a";
    //prepare message elements and send
    $headers = array ('From' => $from,
    'To' => $to,
    'Subject' => $subject, 
    'Content-Type' => "text/html;charset=utf-8", 
    'MIME-Version' => '1.0',
    'Content-Transfer-Encoding' => '8bit'
    );
    $mimeparams['text_encoding']="8bit"; 
    $mimeparams['text_charset']="UTF-8"; 
    $mimeparams['html_charset']="UTF-8"; 
    $mimeparams['head_charset']="UTF-8"; 
    $body = $mime->get($mimeparams);    
    $smtp = Mail::factory('smtp',
    array ('host' => $host,
        'port' => $port,
        'auth' => true,
        'username' => $username,
        'password' => $password));
    $body = $mime->get();
    $headers = $mime->headers($headers);
    $recipients = $to.", ".$bcc;
    $mail = $smtp->send($recipients , $headers, $body);

相关内容

最新更新