Jump to content

eMail form with a PHP, no special characters in the PHP response HELP PLEASE


Onzeon

Recommended Posts

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 = "myemail@me.com";

    $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

}

?>

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

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.