自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

PHP mail()函數(shù)亂碼的具體解決方法

開發(fā) 后端
PHP mail()函數(shù)亂碼出現(xiàn)的原因一般是函數(shù)中header參數(shù)缺少Content-type: text/html; charset=utf-8等原因引起的。

我們在使用PHP語言進行代碼編程,處理中文字符時經常會遇到亂碼出現(xiàn)的問題。我們今天就為大家介紹有關PHP mail()函數(shù)亂碼的具體解決辦法。#t#

一般這種問題出現(xiàn)的原因是 mail() 函數(shù)的 header 參數(shù)里少了 Content-type: text/html; charset=utf-8,或者 charset 不是utf-8。很多國外的PHP程序一開始開發(fā)的時候沒有吧中文考慮進去,所以中文使用的時候就會出現(xiàn)PHP mail()函數(shù)亂碼。

先用函數(shù)base64_encode() 使用 MIME base64 對數(shù)據(jù)進行編碼
標題字符串前加編碼類型例如: =?UTF-8?B?
當然如果是gb2312的話就 =?GB2312?B?
標題字符串后加:?=

PHP mail()函數(shù)亂碼的處理辦法舉例如下
 

  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 <
    < a href="mailto:xinple@example.com">
    xinple@example.com</a>&gt;'
     . "\r\n";  
  7. $headers .'From: Admin &lt;
    <a href="mailto:admin@example.com">
    admin@example.com</a>&gt;'
     . "\r\n";  
  8. $headers .'Reply-To: Xinple &lt;xinple@example&gt;' . "\r\n";  
  9. mail($to, $subject, $message, $headers); 

以上就是PHP mail()函數(shù)亂碼的具體處理辦法,希望對有需要的朋友有所幫助。

責任編輯:曹凱 來源: yaoyingying.com
相關推薦

2009-11-26 15:42:18

PHP函數(shù)mail()

2009-12-02 16:53:25

PHP發(fā)送郵件亂碼

2009-12-04 16:49:38

PHP導出Excel亂

2009-09-07 18:40:28

PHP中文亂碼

2010-07-15 14:01:12

telnet亂碼

2009-12-09 15:23:36

PHP mail()函

2010-10-13 17:22:12

MySQL查詢亂碼

2011-01-21 16:40:58

NagiosSendmail

2011-03-01 15:38:44

Fireftp亂碼

2009-06-25 15:06:20

Javadoc亂碼

2009-11-30 10:55:16

PHP頁面亂碼

2009-12-03 17:18:15

PHP strtoti

2009-07-01 18:14:36

JSP亂碼

2009-12-07 16:52:59

PHP函數(shù)getima

2011-03-11 10:39:07

LAMPPHP

2010-02-24 16:30:52

WCF常見錯誤

2013-01-30 16:54:21

2009-07-02 13:26:32

JSP中文亂碼

2011-09-06 16:04:59

Ubuntu

2010-10-14 13:45:44

MySQL函數(shù)不能創(chuàng)建
點贊
收藏

51CTO技術棧公眾號