我正拼命想让西班牙语字符在我发送的MIME电子邮件中正确显示。
因此,经过几个小时的搜索,我尝试了以下方法,但没有成功。
在我的PHP中添加了以下内容:
mb_internal_encoding("UTF-8");
header('Content-Type: text/html; charset=utf-8');
确保我的文件在notepad ++中以UTF8格式
在我的HTML代码中添加了以下内容:
<meta http-equiv='Content-Type' content='text/html; charset=UTF-8'>
在我的my.cnf文件中添加了以下内容并重新启动了服务器:
init-connect='SET NAMES utf8'
确保所有表格都在utf8_unicode_ci
在选择查询之前的查询中添加了以下内容:
SET NAMES utf8;
我正在使用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);
我希望有人能指出我正确的方向。
答案 0 :(得分:3)
不要使用自己的解决方案撰写和发送电子邮件,你可能会弄错。使用一些电子邮件类,例如PHPMailer。只设置了CharSet属性:
$mailer = new PHPMailer();
$mailer->CharSet = 'utf-8';
根据documentation,您可以传递head_charset,text_charset和html_charset参数。您传递给$ mime-&gt; headers()的内容类型标题可能会被覆盖。
答案 1 :(得分:1)
问题很简单:使用西班牙语时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中使用西班牙语,那么您必须遵循:
对每个符号进行编码,否则将无效:
á -> á
é -> é
í -> í
ó -> ó
ú -> ú
ñ -> ñ
谁...创建了UTF-8?
答案 2 :(得分:0)
我想出来了。这是mime电子邮件的一个问题。
// 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);