PHP Mail标头,用于主题或消息中带有特殊字符的电子邮件 [英] PHP Mail header for emails with special characters in the subject or message

查看:215
本文介绍了PHP Mail标头,用于主题或消息中带有特殊字符的电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码:

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

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: øʼªʼ

提前谢谢!

推荐答案

内容类型:text/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\r\n"; 
$header.= "MIME-Version: 1.0\r\n"; 
$header.= "Content-Type: text/plain; charset=utf-8\r\n"; 
$header.= "X-Priority: 1\r\n"; 

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

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆