我在身体消息中遇到php charset问题。邮件中包含以下字符:žřýžž¾¾>ýážýü½Å¾Ã
我的contact.php
<?php
//if "email" variable is filled out, send email
if (isset($_REQUEST['email'])) {
//Email information
$admin_email = "mail@gmail.com";
$email = $_REQUEST['email'];
$subject = 'Message';
$comment = $_REQUEST['comment'];
//send email
mail($admin_email, "$subject", $comment, "From:" . $email);
//Email response
echo "OK";
}
//if "email" variable is not filled out, display the form
else {
?>
<form method="post">
Email: <input name="email" type="text" /><br />
Subject: <input name="subject" type="text" /><br />
Message:<br />
<textarea name="comment" rows="15" cols="40"></textarea><br />
<input type="submit" value="Submit" />
</form>
<?php
}
?>
拜托,你能帮助我使用UTF8吗?非常感谢你
答案 0 :(得分:0)
尝试使用php邮件程序类并告诉它:
$mail->CharSet='UTF-8';
$mail->Subject=utf8_encode("=?UTF-8?B?".base64_encode('you utf8 string')."?=");
或者,如果您不想使用php邮件程序类,您可以随时使用翻译功能:
str_replace(
array(,'¡','¿','á','é','í','ñ','ó','ú','Á','É','Í','Ñ','Ó','Ú'),
array('¡','¿','á','é','í','ñ','ó','ú','Á','É','Í','Ñ','Ó','Ú'),
$yourstring
);
我的例子是拉丁语(西班牙语)字母,
答案 1 :(得分:0)
尝试在表单上使用此方法强制使用utf-8编码
<form method="post" action="/your/url/" accept-charset="UTF-8">
答案 2 :(得分:0)
您是否尝试在脚本页面的标题中添加元数据? 如下:
<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head>
答案 3 :(得分:0)
确保您到处使用UTF8
!
php ** header()**
<?php header("Content-type: text/html; charset=utf-8"); ?>
和
html meta
代码
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />