编码 - 在HTML和PHP中使用表单加重

时间:2016-06-23 00:40:38

标签: php html5 encoding

我是一个以html格式插入的表单的重音问题。我已经尝试过各种方式来使用google上一个好搜索范围内的所有内容,但我无法解决问题。对于角色不断疯狂的方式。

电子邮件:root@example.com

Nome:Ração

Comentário:Ração

请按照以下脚本操作。

HTML

                <form class="form-inline" role="form" method=post  accept-charset="UTF-8" >
                  <div class="form-group">
                    <label class="sr-only" for="exampleInputEmail2">Email</label>

                    <input type=email class="form-control transparent" name="Email" placeholder="Email" required > 

                    <input type=text class="form-control transparent" name="Nome" size=25 placeholder="Nome" required >

                    <input type=text class="form-control transparent" name="WhatsApp" size=25 placeholder="WhatsApp: Ex: 11 - 8888 - 9999 "  > 

                    <textarea  rows=4 cols=30 class="form-control transparent" name="Comentário" placeholder="Sua linda mensagem, aqui ♥" required></textarea>

                    <div style="color: #fff; font-size: 12px; margin-bottom: 30px; margin: 0 auto 30px; text-align: center;">
                      <input type="radio" name="AntiSpam" required /> ← Marque antes de enviar </div></div>

<button class="btn btn-danger btn-fill" type="submit" >Enviar</button></form>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>

<script>$('.form-inline').attr('action', 'mail.php');</script>

PHP

 <?php header('Content-Type: text/html; charset=UTF-8');
$sendFrom =    "Contato TopMágico <contato@topmagico.com.br>";

$sendTo =      "foo@gmail.com";

$subjectLine = "Contato TopMágico";

$thanksURL =   "gratidao.php";   

foreach ($_POST as $field=>$value)
   $msgBody .= "$field: $value\n";

$msgBody .= "\n" . @gethostbyaddr($_SERVER["REMOTE_ADDR"]) . "\n" . $_SERVER["HTTP_USER_AGENT"];

$msgBody = htmlspecialchars($msgBody, ENT_NOQUOTES);  //make safe
$spam = count($_POST) == 0 || stristr($msgBody, "cc: ") ||
          stristr($msgBody, "href=") || stristr($msgBody, "[url");

      if (!$spam)
          mail($sendTo, $subjectLine, $msgBody, "From: $sendFrom"); 
header("Location: $thanksURL");
?>

1 个答案:

答案 0 :(得分:0)

尝试在HTML文件中将元字符集添加/更改为UTF8

<meta charset="UTF-8" />

如果不起作用,请将其更改为

<meta charset="ISO-8859-1" />