Jump to content

Recommended Posts

Posted

Ora viva pessoal,

estou aqui com um problema que não estou a conseguir contornar. Tenho um formulário em html no qual tudo aparece bem, contudo quando recebo a informação, a acentuação vem toda marada.

Ambos os ficheiros estao codificados com UTF-8, contudo, penso que seja no PHP que resida o problema... acho que os headers deveriam ser assim:

$headers = "MIME-Version: 1.0\n";

$headers .= "Content-type: text/html; charset=UTF-8\n";

mas já experimentei acrescentar isso e não resolve!

Se alguém me poder ajudar agradecia!

Abr

O MEU CÓDIGO HTML

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Formulário contacto site EPV</title>
</head>

<body>
<form id="form1" name="form1" method="post" action="verificar.php">
  <table width="419" border="0" cellpadding="2" cellspacing="0" bordercolor="#000000">
    <!--DWLayoutTable-->
    <tr>
      <td colspan="2"><p>
        
      </p>
      <p align="center" class="style2">Formulário de contacto </p>
      <p align="center" class="style9">Campos assinalados com (*) são obrigatórios</p>      </td>
    </tr>
    <tr>
      <td><span class="style2">Nome:</span></td>
      <td><input name="nome" type="text" id="nome" size="40" maxlength="45" /> 
        <span class="style11">*</span></td>
    </tr>
    <tr>
      <td><span class="style2">Localidade:</span> </td>
      <td><input name="morada" type="text" id="morada" size="40" maxlength="55" /></td>
    </tr>
    <tr>
      <td><span class="style13"><span class="style14">Telefone</span>:</span></td>
      <td><input name="tel" type="text" id="tel" size="40" maxlength="9" /> <span class="style11">*</span></td>
    </tr>
    <tr>
      <td><span class="style2">E-mail:</span></td>
      <td><input name="email" type="text" id="email" size="40" maxlength="25" /> 
        <span class="style11">*</span></td>
    </tr>
    <tr>
      <td><strong><span class="style2">Produto:</span></strong></td>
      <td>
      <input type="checkbox" name="group2" value="familiar" />
      <span class="style11">      Familiar</span> 
      <input type="checkbox" name="group2" value="negocio" /> 
      <span class="style11">Negócio      </span>
      <input type="checkbox" name="group2" value="financeira" /> 
      <span class="style11">Financeira </span></td>
    </tr>
    <tr>
      <td class="style2">Mensagem:</td>
      <td><textarea name="textarea" cols="38" rows="4" onblur=""></textarea></td>
    </tr>
    <tr>
      <td> <p> </p>
      <p> </p></td>
      <td><input name="Enviar" type="submit" id="Enviar" onclick= value="Enviar" value="Enviar" />
      <input name="Corrigir" type="reset" id="Corrigir" value="Limpar" /></td>
    </tr>
  </table>
</form>
<body>
</body>
</html>

O MEU CÓDIGO PHP

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Formulário contacto site EPV</title>

<body>

<?php

$nome=$_POST["nome"];
$email=$_POST["email"];
$tel=$_POST["tel"];
if (empty($nome))
{
echo "<span style='color: rgb(251, 131, 2);'>/!\ Nome, Email e Telefone são obrigatórios /!\</span>";
include 'formulario.html';

}
elseif (empty($email))
{
echo "<span style='color: rgb(251, 131, 2);'>/!\ Nome, Email e Telefone são obrigatórios /!\</span>";
include 'formulario.html';
}

elseif (!$email == "" && (!strstr($email,"@") || !strstr($email,"."))) 
{
echo "<span style='color: rgb(247, 107, 31);'>/!\ Email não é válido /!\</span>";
include 'formulario.html';
}

else
{
$message = "Nome: " . $_POST['nome'] . "\n";
$message .= "Morada: " . $_POST['morada'] . "\n";
$message .= "Telefone: " . $_POST['tel'] . "\n";
$message .= "Email: " . $_POST['email'] . "\n";
$message .= "Produto: " . $_POST['group2'] . "\n";
$message .= "Mensagem: " . $_POST['textarea'] . "\n";

mail("email@email.pt","Formulário contacto site EPV",$message, "From:" . $_POST['email'] );

echo "<span style='color: rgb(255, 255, 255);'>/!\ Dados enviados com sucesso. /!\</span>";
include 'formulario.html';
}

?> 

</body>
</html>

E AQUI O QUE RECEBO NO EMAIL:

Nome: teste
Morada: testeséa
Telefone: 233523523
Email: fdgsdfgh@cfgdfg.fdgj
Produto: financeira
Mensagem: fgjdfgjdfé zgz ç z dfzsdá 
Posted

Viva!

Fiz o seguinte no meu código:

PHP

<?php
header('Content-Type: text/html; charset=utf-8'); 
mysql_query("SET NAMES 'utf8'");
mysql_query('SET character_set_connection=utf8');
mysql_query('SET character_set_client=utf8');
mysql_query('SET character_set_results=utf8');	
...
...
?>

E utilizas a seguinte tag no HTML:

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.