Onzeon Posted May 19, 2011 Share Posted May 19, 2011 Hello PHP GURUS. I have this PHP code for my HTML email form. This site is in Brazil, so most people requesting information and using the form write in portuguese using the language characters. (ã, é, ó, ç, í and others). When I get the response back, all the special characters are replaced by different characters (like they are not available in the font family) like this: Gostaria de uma informação de vocês. What we get is: Gostaria de uma informação de vocês. (in the courier font) We dont know if it is the font family or the server that is eliminating/replacing the characters. Is there a way to force these characters by specifying a font-family in the PHP code for the body of the email? Thank you very much for taking the time to even read this. Here is my code: <?php if(isset($_POST['email'])) { // EDIT THE 2 LINES BELOW AS REQUIRED $email_to = "[email protected]"; $email_subject = "Pedido para contato"; function died($error) { // your error code can go here echo "Lamentamos muito, mas houve erro(s) encontrado com a forma que voce enviou. "; echo "Esses erros aparecem abaixo.<br /><br />"; echo $error."<br /><br />"; echo "Por favor, volte para corrigir esses erros.<br /><br />"; die(); } // validation expected data exists if(!isset($_POST['first_name']) || !isset($_POST['last_name']) || !isset($_POST['email']) || !isset($_POST['telephone']) || !isset($_POST['comments'])) { died('Lamentamos, mas parece haver um problema com a forma que voce enviou.'); } $first_name = $_POST['first_name']; // required $last_name = $_POST['last_name']; // required $email_from = $_POST['email']; // required $telephone = $_POST['telephone']; // not required $comments = $_POST['comments']; // required $error_message = ""; $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/'; if(!preg_match($email_exp,$email_from)) { $error_message .= '- O endereco de e-mail que voce digitou nao parece ser valido.<br />'; } $string_exp = "/^[A-Za-z .'-]+$/"; if(!preg_match($string_exp,$first_name)) { $error_message .= '- O nome que voce digitou nao parece ser valido.<br />'; } if(!preg_match($string_exp,$last_name)) { $error_message .= '- O Sobre Nome que voce digitou nao parece ser valido.<br />'; } if(strlen($comments) < 2) { $error_message .= '- O pedido de informacao que voce digitou nao parece ser valido.<br />'; } if(strlen($error_message) > 0) { died($error_message); } $email_message = "Detalhes da forma a baixo.\n\n"; function clean_string($string) { $bad = array("content-type","bcc:","to:","cc:","href"); return str_replace($bad,"",$string); } $email_message .= "Nome: ".clean_string($first_name)."\n"; $email_message .= "Sobre Nome: ".clean_string($last_name)."\n"; $email_message .= "Email: ".clean_string($email_from)."\n"; $email_message .= "Telefone: ".clean_string($telephone)."\n"; $email_message .= "Informacao pedida: ".clean_string($comments)."\n"; // create email headers $headers = 'From: '.$email_from."\r\n". 'Reply-To: '.$email_from."\r\n" . 'X-Mailer: PHP/' . phpversion(); @mail($email_to, $email_subject, $email_message, $headers); ?> success <?php } ?> Quote Link to comment https://forums.phpfreaks.com/topic/236894-email-form-with-a-php-no-special-characters-in-the-php-response-help-please/ Share on other sites More sharing options...
Stooney Posted May 19, 2011 Share Posted May 19, 2011 It's a character encoding issue. When setting the headers, you need to set charset= to the correct charset. Quote Link to comment https://forums.phpfreaks.com/topic/236894-email-form-with-a-php-no-special-characters-in-the-php-response-help-please/#findComment-1217753 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.