[英]Encoding problem in From email and name when sending email in PHP?
What could be causing this encoding problem? 什么可能导致这种编码问题? Am I encoding the header information correctly or could this be caused somewhere else?
我是否正确编码标题信息或者是否可能在其他地方引起?
I found a similar problem here: Email from PHP has broken Subject header encoding but from what I'm reading I think I'm doing this right. 我在这里发现了一个类似的问题: 来自PHP的电子邮件已经破坏了主题标题编码但是从我正在阅读的内容中我认为我正在这样做。
Basically sometimes our clients send emails written in french. 基本上有时我们的客户会发送用法语写的电子邮件。 It works but every once in a while we get some encoding issues and I'm wondering if I did the encoding wrong (I can't figure out).
它工作但偶尔我们得到一些编码问题,我想知道我是否编码错误(我无法弄清楚)。
$from = '=?UTF-8?B?'.base64_encode($email['from_name']).'?= <'.$email['from_email'].'>';
$to = '=?UTF-8?B?'.base64_encode($email['to_name']).'?= <'.$email['to_email'].'>';
$get_param = array(
'Content-Type' => 'text/plain;charset=utf-8',
'Content-Transfer-Encoding' => '8bit');
The code above is how I encode my header information and below is the sending: 上面的代码是我如何编码我的头信息,下面是发送:
$msg = $message_mime->get($get_param);
$headers = array (
'From' => $from,
'To' => $to,
'Reply-To' => $from,
'Subject' => utf8_decode($subject));
$headers = $message_mime->headers($headers);
$smtp = Mail::factory('smtp',
array ('host' => $smtp_settings['host'],
'auth' => true,
'username' => $smtp_settings['username'],
'password' => $smtp_settings['password']));
$mail = $smtp->send($to, $headers, $msg);
The problem is that the email they received was from: 问题是他们收到的电子邮件来自:
Clientnamé de l'Ontario[=?UTF-8B?QXNzZW1ib(...)=?=]
Thanks for any help :) 谢谢你的帮助 :)
Edit: The client's name basically uses the same characters as above. 编辑:客户端的名称基本上使用与上面相同的字符。 What I mean is that the email was supposed to be from "Clientnamé de l'Ontario"
我的意思是该电子邮件应该来自“Clientnamédel'Ontario”
Did you try replacing base64_encode
with utf8_encode
? 您是否尝试使用
utf8_encode
替换base64_encode
?
I'd try replacing: 我试着替换:
$from = '=?UTF-8?B?'.base64_encode($email['from_name']).'?= <'.$email['from_email'].'>';
$to = '=?UTF-8?B?'.base64_encode($email['to_name']).'?= <'.$email['to_email'].'>';
with: 有:
$email['from_name'] = utf8_encode($email['from_name']);
$email['to_name'] = utf8_encode($email['to_name']);
$from = $email['from_name'].' <' . $email['from_email'] . '>';
$to = $email['to_name']) . ' <' . $email['to_email'] . '>';
Might be worth a try... 也许值得尝试一下...
Also detect_encoding could help ( http://php.net/mb_detect_encoding/ )? detect_encoding也可以提供帮助( http://php.net/mb_detect_encoding/ )?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.