zoukankan      html  css  js  c++  java
  • 解决php中用mail发邮件时标题出现乱码

    php程序使用mail()函数发送邮件的时候,标题中文的话会出现乱码。

    解决方法:
    先用函数base64_encode() — 使用 MIME base64 对数据进行编码
    标题字符串前加编码类型例如: =?UTF-8?B?
    标题字符串后加:?=
    邮件header说明Content-type — 防止邮件正文也乱码

    1. $to         = xinple@example.com;
    2. $subject  = =?UTF-8?B?.base64_encode(邮件标题).?=;
    3. $headers  = MIME-Version: 1.0 . \r\n;
    4. $headers .= Content-type: text/html; charset=utf-8 . \r\n;
    5. // Additional headers
    6. $headers .= To: Xinple <xinple@example.com> . \r\n;
    7. $headers .= From: Admin <admin@example.com> . \r\n;
    8. $headers .= Reply-To: Xinple <xinple@example> . \r\n;
    9. mail($to, $subject, $message, $headers);
  • 相关阅读:
    Linux安装步骤
    Python邮件发送
    拉链表
    Hive
    Shell笔记
    Hadoop入门
    Thinkphp手把手练习
    Shell学习日记
    Linux安装mysql数据库
    Oracle集合操作
  • 原文地址:https://www.cnblogs.com/studio313/p/1061361.html
Copyright © 2011-2022 走看看