Why isn’t my form accepting accents?

Asked

Viewed 72 times

-1

I created a form with php sending the data to my email, but the data that contains accents get distorted and bad to read. Example: "Frog test number 29"

PHP code:

$destinatario = "[email protected]";
$assunto = "FORMULARIO SITE";

$nome = $_REQUEST['name'];
$email = $_REQUEST['email'];
$telefone = $_REQUEST['fone'];
$mensagem = $_REQUEST['message'];


 // monta o e-mail na variavel $body

$body = "===================================" . "\n";
$body = $body . "CONTATO FORMULÁRIO DO SITE" . "\n";
$body = $body . "===================================" . "\n\n";
$body = $body . "Nome: " . $nome . "\n";
$body = $body . "telefone: " . $telefone . "\n";
$body = $body . "Email: " . $email . "\n";
$body = $body . "-----------------------------------" . "\n";
$body = $body . "Mensagem: " . $mensagem . "\n\n";
$body = $body . "===================================" . "\n";

// envia o email
mail($destinatario, $assunto , $body, "From: $email\r\n");


die( 'Sua Mensagem foi enviada. Obrigado!');

1 answer

0


You need to add a Header to your email form and specify the language encoding, as in the example below:

        $destinatario = "[email protected]";
        $remetente = "[email protected]";
        $subject = "Assunto do email";
        $mensagem = "Mensagem do email";
        $headers = "MIME-Version: 1.1\n";
        $headers .= "Content-type: text/plain; charset=utf-8\n";
        $headers .= "From: NOME DE QUEM ESTA ENVIANDO <" . $remetente . ">\n";
        $headers .= "Reply-To: " . $remetente . "\n";
        
        mail($destinatario, $subject, $mensagem, $headers); 

If sending an HTML message change Content-type to text/html

  • Solved it right, thank you!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.