主题或消息中包含特殊字符的电子邮件的 PHP 邮件标头

PHP Mail header for emails with special characters in the subject or message(主题或消息中包含特殊字符的电子邮件的 PHP 邮件标头)
本文介绍了主题或消息中包含特殊字符的电子邮件的 PHP 邮件标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码:

$to      = 'example@example.com';
$subject = $_REQUEST['subject'] ;
$message = $_REQUEST['message'] ;
$header = "From: noreply@example.com
"; 
$header.= "MIME-Version: 1.0
"; 
$header.= "Content-Type: text/html; charset=ISO-8859-1
"; 
$header.= "X-Priority: 1
"; 

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

当我发送带有特殊字符的邮件时,例如 ®ð-˚©-ʼæ,˚ˍðß©,在消息中,它可以工作,但不再处理间距(每个新行或空格都被删除)第二个问题是主题中没有显示特殊字符.他们只是输出如下: øʼªʼ

When i send a mail with special characters such as ®ð-˚©-ʼ"æ,˚ˍðß©, in the message, it works but spacing is no longer dealt with (every new line or space gets removed) And the second problem is that the special characters are not displayed in the subject. They just output like: øʼªʼ

提前致谢!

推荐答案

内容类型:文本/html

Content-Type: text/html

如果您设置此标头,则意味着您必须将 HTML 发送给用户.您可以决定使用 TinyMCE 之类的工具,让用户在 Word 样式的编辑器中编写消息,并使用其中的 HTML 输出.或者将您的标题设置为纯文本.

If you set this header that means you have to send HTML to the user. You can either decide to use something like TinyMCE to let the user write the message in a Word-style editor and use the HTML output from that. Or set your headers to plaintext.

内容类型:文本/纯文本

Content-Type: text/plain

试试这个

$to      = 'example@example.com';
$subject = $_REQUEST['subject'] ;
$message = $_REQUEST['message'] ;
$header = "From: noreply@example.com
"; 
$header.= "MIME-Version: 1.0
"; 
$header.= "Content-Type: text/plain; charset=utf-8
"; 
$header.= "X-Priority: 1
"; 

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

这篇关于主题或消息中包含特殊字符的电子邮件的 PHP 邮件标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Convert JSON integers and floats to strings(将JSON整数和浮点数转换为字符串)
in php how do I use preg replace to turn a url into a tinyurl(在php中,如何使用preg替换将URL转换为TinyURL)
all day appointment for ics calendar file wont work(ICS日历文件的全天约会不起作用)
trim function is giving unexpected values php(Trim函数提供了意外的值php)
Basic PDO connection to MySQL(到MySQL的基本PDO连接)
PHP number_format returns 1.00(Php number_Format返回1.00)