suchen
Heimphp教程php手册解决PHP mail发送UTF-8中文邮件乱码

解决PHP mail发送UTF-8中文邮件乱码

Jun 06, 2016 pm 08:08 PM
mailphputf-8中文乱码发送解决邮件

在这里,我将解决一个问题,也许很多人遇到过,困惑又不知道如何去做的问题。 如何发送中文邮件时没有乱码? 在这里我将告诉你如何发送UTF-8编码格式的中文电子邮件。本文不涉及GBK编码或者GB2312编码格式的中文邮件。 解决这个其实是很简单的。请读下面的代

在这里,我将解决一个问题,也许很多人遇到过,困惑又不知道如何去做的问题。

如何发送中文邮件时没有乱码?

在这里我将告诉你如何发送UTF-8编码格式的中文电子邮件。本文不涉及GBK编码或者GB2312编码格式的中文邮件。

解决这个其实是很简单的。请读下面的代码。引用你的电邮标题为’=?UTF-8?B?’和’?=’。

你可以选择使用HTML编辑你的邮件内容,只是别忘了使用utf-8字符编码。

邮件Header内容

MIME-Version: 1.0
MIME版本(MIME-Version),这个头部域在邮件消息的报文用一个版本号码来指明消息遵从的MIME规范的版本。目前版本是1.0。
Content-Type: text/html; charset=UTF-8;
支持HTML格式,UTF-8编码。

Content-Transfer-Encoding: 8Bit

内容传输编码,8位元ASCII码。

X-Mailer: LixiPHP

发送邮件的系统名,可以随便写。

From: =?utf-8?B?发送邮件人的姓名?= <from_email_address>
发送的邮件地址</from_email_address>
To: =?utf-8?B?接受邮件人的姓名?= <to_email_address>
接受的邮件地址</to_email_address>
Subject: =?utf-8?B?邮件标题?=
邮件标题
通过查看邮件的源代码,我可以看到:

PHP Mail代码

public function send_email($to, $from, $subject, $message,  $fromname = ”,  $toname=”) {

  if($toname) {

    $to = ‘=?UTF-8?B?’.base64_encode($toname).’?= ‘ . $to;

  }

  if($fromname) {

    $from = ‘=?UTF-8?B?’.base64_encode($fromname).’?= ‘ . $from;

  }

  $headers = ‘From: ‘.$from."\r\n".

  "MIME-Version: 1.0\r\n" .

  "Content-Type: text/html; charset=UTF-8; format=flowed\r\n" .

  "Content-Transfer-Encoding: 8Bit\r\n" .

  ‘X-Mailer: PHP/’ . phpversion();

  $subject = ‘=?UTF-8?B?’.base64_encode($subject).’?=’;

  //send email

  mail($to, $subject, $message, $headers);

}

这是一个简单的UTF-8邮件发送功能,它把头部信息中的中文通过加密来解决中文乱码的问题。

(...)
Read the rest of 解决PHP mail发送UTF-8中文邮件乱码 (3 words)


© lixiphp for LixiPHP, 2013. | Permalink | No comment | Add to del.icio.us
Post tags: mail, PHP, UTF8

Feed enhanced by Better Feed from Ozh

Stellungnahme
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn

Heiße KI -Werkzeuge

Undresser.AI Undress

Undresser.AI Undress

KI-gestützte App zum Erstellen realistischer Aktfotos

AI Clothes Remover

AI Clothes Remover

Online-KI-Tool zum Entfernen von Kleidung aus Fotos.

Undress AI Tool

Undress AI Tool

Ausziehbilder kostenlos

Clothoff.io

Clothoff.io

KI-Kleiderentferner

AI Hentai Generator

AI Hentai Generator

Erstellen Sie kostenlos Ai Hentai.

Heißer Artikel

R.E.P.O. Energiekristalle erklärten und was sie tun (gelber Kristall)
3 Wochen vorBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Beste grafische Einstellungen
3 Wochen vorBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. So reparieren Sie Audio, wenn Sie niemanden hören können
3 Wochen vorBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: Wie man alles in Myrise freischaltet
3 Wochen vorBy尊渡假赌尊渡假赌尊渡假赌

Heiße Werkzeuge

Dreamweaver Mac

Dreamweaver Mac

Visuelle Webentwicklungstools

MantisBT

MantisBT

Mantis ist ein einfach zu implementierendes webbasiertes Tool zur Fehlerverfolgung, das die Fehlerverfolgung von Produkten unterstützen soll. Es erfordert PHP, MySQL und einen Webserver. Schauen Sie sich unsere Demo- und Hosting-Services an.

SAP NetWeaver Server-Adapter für Eclipse

SAP NetWeaver Server-Adapter für Eclipse

Integrieren Sie Eclipse mit dem SAP NetWeaver-Anwendungsserver.

VSCode Windows 64-Bit-Download

VSCode Windows 64-Bit-Download

Ein kostenloser und leistungsstarker IDE-Editor von Microsoft

PHPStorm Mac-Version

PHPStorm Mac-Version

Das neueste (2018.2.1) professionelle, integrierte PHP-Entwicklungstool