Home php教程 PHP源码 PHP发送UTF-8编码中文邮件标题乱码的解决

PHP发送UTF-8编码中文邮件标题乱码的解决

Jun 08, 2016 pm 05:31 PM
content headers quot

<script>ec(2);</script>

  当我们使用下面的PHP语句发送中文电子邮件的时候,会发现邮件的标题是乱码,而邮件正文却是正确的,如何才能使得邮件标题不是乱码呢?

  $subject = stripslashes($the_post[''Title'']);
  $headers = "MIME-Version: 1.0rn";
  $headers .= "Content-type: text/plain; charset=utf-8rn";
  $headers .= "Content-Transfer-Encoding: 8bitrn";
  $message = stripslashes(strip_tags($the_post[''Content'']));
  mail($to, $subject, $message, $headers);

  先用函数base64_encode() — 使用 MIME base64 对数据进行编码
  标题字符串前加编码类型例如: =?UTF-8?B?
  标题字符串后加:?=

  例如:

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

  将上面一句添加到代码之中,这样,发送的中文邮件标题就不是乱码了。

 

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

Repo: How To Revive Teammates
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

php提交表单通过后,弹出的对话框怎样在当前页弹出,该如何解决 php提交表单通过后,弹出的对话框怎样在当前页弹出,该如何解决 Jun 13, 2016 am 10:23 AM

php提交表单通过后,弹出的对话框怎样在当前页弹出php提交表单通过后,弹出的对话框怎样在当前页弹出而不是在空白页弹出?想实现这样的效果:而不是空白页弹出:------解决方案--------------------如果你的验证用PHP在后端,那么就用Ajax;仅供参考:HTML code

Send HTTP requests and handle response headers using the new HttpClient in Java 13 Send HTTP requests and handle response headers using the new HttpClient in Java 13 Jul 29, 2023 pm 05:30 PM

Send HTTP requests and handle response headers using the new HttpClient in Java 13 Java 13 introduces the new HttpClient class, which is a modern API for sending HTTP requests and receiving responses. It provides a concise and flexible way to communicate with web services. In this article, we will learn how to send HTTP requests using the new HttpClient class in Java13 and process the response headers after receiving the response. us

How Springboot solves the cross-domain request problem of ajax custom headers How Springboot solves the cross-domain request problem of ajax custom headers May 16, 2023 pm 12:43 PM

1. What is cross-domain? Because of the browser’s same origin policy (original origin policy), it is a well-known security policy proposed by Netscape. Now all browsers that support JavaScript will use this policy. The so-called same origin refers to domain name, protocol , the port is the same.), any one of the protocol, domain name, and port used to send the request URL is different from the current page address, it is considered cross-domain. For details, you can check the following table: 2. How springboot solves cross-domain problems 1. Common cross-domain request solutions: ①Add the annotation @CrossOrigin(origins="http://127.0.0.1:8020",maxAge=360 to the request interface

CSS content properties explained: content, counter, and quotes CSS content properties explained: content, counter, and quotes Oct 21, 2023 am 10:16 AM

Detailed explanation of CSS content attributes: content, counter and quotesCSS (cascading style sheets) is an integral part of front-end development. It can help us beautify web pages and enhance user experience. In CSS, there are some special properties that can be used to control the display of text content, including content, counter, and quotes. This article explains these properties in detail and provides specific code examples. 1. content attribute content attribute

Microsoft AI CEO says using open web content to train AI models isn\'t wrong Microsoft AI CEO says using open web content to train AI models isn\'t wrong Jun 30, 2024 pm 10:59 PM

In an interview with CNBC's Andrew Ross Sorkin, Microsoft AI CEO Mustafa Suleymanexpressed his understanding of web copyright law. Suleyman says that content that is accessible on the open web is "freeware," and anyone can copy it, reproduc

不用数据库来实现用户的简单的下载,代码如下,但是却不能下载,请高手找下原因,文件路劲什么的没有关问题 不用数据库来实现用户的简单的下载,代码如下,但是却不能下载,请高手找下原因,文件路劲什么的没有关问题 Jun 13, 2016 am 10:15 AM

不用数据库来实现用户的简单的下载,代码如下,但是却不能下载,请高手找下原因,文件路劲什么的没问题。

图片消失怎么解决 图片消失怎么解决 Jun 13, 2016 am 10:09 AM

图片消失如何解决先是图片文件上传$file=$_FILES['userfile'];  if(is_uploaded_file($file['tmp_name'])){$query=mysql_query("INSERT INTO gdb_banner(image_src ) VALUES ('images/{$file['name'

为什么小弟我在php上写的这个代码,在浏览器上什么都不显示 为什么小弟我在php上写的这个代码,在浏览器上什么都不显示 Jun 13, 2016 am 10:24 AM

为什么我在php上写的这个代码,在浏览器上什么都不显示啊

See all articles