dtslobe4694 2012-10-18 18:04
浏览 50

mail()有效,而mb_send_mail()不在多字节环境中

Lately, we have transitioned our environment over to use UTF-8 encoding. Everything seemed to be working perfectly. Pages were being served up correctly in UTF-8 and email sent with PHP's mail() function were also being sent with (in our case) French characters appearing properly.

This morning, I started substituting non-multi-byte string functions (e.g., strlen(), mail()) with their multi-byte counterpart (e.g., mb_strlen(), mb_send_mail()) and it appears to be working as expected in all cases, except for mb_send_mail(), where French characters appear as question marks. Oddly, they appear correctly when using mail(). I also have the charset set to utf-8 in the email's headers in both cases, and checking it in my email client confirms that it is sent as such.

I should add that I am not using the Function Overloading feature, because I was concerned it would interfere with third-party extensions we are using, which is why I have chosen to replace the functions manually.

EDIT

These lines were modified/added in php.ini:

default_charset = "utf-8"
mbstring.language=Neutral
mbstring.internal_encoding=utf-8
mbstring.http_input=UTF-8
mbstring.http_output=UTF-8
mbstring.encoding_translation=On

My PHP files are also all saved in UTF-8 encoding, without BOM.

The code when calling the mb_send_mail() function looks like this:

$to = "person@email.com";
$subject = "Assigné";
$body = "La demande suivante vous a été assigné : "
$headers .= 'From: ' . $from . "
";
$headers .= 'MIME-Version: 1.0' . "
";
$headers .= 'Content-Type: text/html; charset="utf-8"' . "
";
$headers .= 'Content-Transfer-Encoding: quoted-printable' . "
";

if (!(@mb_send_mail($to, $subject, $body, $headers))) {
//Error message
}

As indicated in my original post, when using the mb_send_mail() function, all my e acute (é) characters, including the email's subject and bosy, appear as question marks (?), but when using the mail() function, they appear as intended.

  • 写回答

1条回答 默认 最新

  • doulu0266 2012-10-19 22:41
    关注

    Keep the mail() function it works better as far as I have noticed.

    See PHP manual for mb_send_mail() others recommend it to.

    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?