您好,欢迎访问一九零五行业门户网

PHP mail 中文乱码的解决方式

主要是编码的问题:
解决办法就是: 读取的数据设置好编码方式; 发邮件的时候也指定编码方式;
先用函数base64_encode() 使用 mime base64 对数据进行编码
标题字符串前加编码类型例如: =?utf-8?b?
当然如果是gb2312的话就 =?gb2312?b?
标题字符串后加:?=
-----------我的供配置参考---------
<html> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <body> <?php if(strlen($_post["from"]) > 1) //if "email" is filled out, send email { //send email $email = $_post["from"] ; $mailto = $_post["mailto"]; $subject = "=?utf-8?b?" . base64_encode($_post["subject"]) . "?="; $message = $_post["message"] ; $header = 'mime-version: 1.0' . "\r\n" . "content-type: text/html; charset=utf-8". "\r\n" . "from: <$email>"."\r\n"; //echo "mailto:$mailto<br />", "subject: $subject<br />", "message:$message<br />", "from: $email<br />" ; mail("$mailto", "$subject", $message, "$header" ); echo "<br />your mail has been sent ! thank you for using our mail system ...<br /> we shall go to main page in 3 seconds <br />"; } else{ echo "<center><h2>welcome to qunero-php mail system </h2></center><br />"; echo '<form method="post" action="index.php"> from : <input type="text" name="from" /><br/ > mailto : <input type="text" name="mailto" /><br /> subject : <input type="text" name="subject" /><br /> message : <br /><textarea name="message" rows="15" cols="80"> </textarea><br /> <input type="submit" /> </form>'; } ?> </body> </html>
其它类似信息

推荐信息