Strange characters when receiving contact form content

Asked

Viewed 146 times

0

Simple form for sending email to the user’s inbox, but upon receiving, accented characters arrive distorted.

Example: The word Encoding arrives as "encoding§§§§§§§§§§§\167box. I don’t know if the problem is in the form or code.

PHP of the form: https://codeshare.io/jGzQ9

  • 4
  • see if your html is set to utf-8 and lang, if this happens in php it also checks for it. '<? php header("Content-type: text/html; charset=utf-8"); ? >' '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />' , or you can put it directly in the form '<form Accept-charset="utf-8" ...>'

  • All of the above attributes are already in my HTML, I still added the property in the form; but the error persists.

1 answer

0


all right?!

You need to add one header (header) encoding for the function mail().

<?php
$name = $_POST['nome'];
$email = $_POST['email'];
$message = $_POST['message'];
$formcontent="From: $name \n Message: $message";
$recipient = "[email protected]";
$subject = "Contact Form";

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

mail($recipient, $subject, $formcontent, $headers); or die("Error!");

echo "Obrigado! Entraremos em contato em breve.";
header( "refresh:5;url=index.html");
?>

Take a look at documentation PHP to better understand the function mail().

  • Thank you, both the headers and the read in the documentation were of great value. I ended up incrementing a confirmation with statement if/Else basic. Everything straight here.

  • I’m happy to help you.

Browser other questions tagged

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