0

I have a contact page (contact.php) that sends a form (formsend.php) when people fill in the contact details.

The contact.php has:

<!DOCTYPE html>
  <html lang="pt-br">
    <head>
      <meta charset="ISO-8859-1">

Contact.php page is fine, displays my latin Portuguese characters fine (ã, é, etc).

But when I receive the email (when it uses formsend.php), I get the fields people signed up with messed up characters: João is João, etc.

On formsend.php I've tried adding:

$headers .= "Content-type: text/plain; charset=iso-8859-1\r\n";

and

 header('Content-Type: text/html; charset=iso-8859-1');

and

<!DOCTYPE html>
  <html lang="pt-br">
    <head>
      <meta charset="ISO-8859-1">

as well. Nothing works.

It seems it's the formsend.php file that is failing here.

What can I do to ensure I receive properly formatted characters in the email with the user's info?

6
  • switch the email encoding to utf8.
    – hakre
    Jun 14, 2012 at 21:35
  • @Dagon - it utf-8 is even worse. Characters are not recognizable in either contact.php or sendform.php :(
    – user1220518
    Jun 14, 2012 at 21:42
  • header() is only going to affect the output from server->browser. It will do absolutely NOTHING to the email that gets sent from the script.
    – Marc B
    Jun 14, 2012 at 22:04
  • @Marc B what do you suggest then?
    – user1220518
    Jun 14, 2012 at 22:07
  • Bite the bullet, switch to using UTF-8 throughout your entire pipeline: web pages, database tables/fields, database connection, blah blah blah. if you use a different charset at ANY point in the pipeline, you're going to get corrupted characters.
    – Marc B
    Jun 14, 2012 at 22:08

1 Answer 1

1

Yes you may try to switch utf-8: and also do not forget to change header info header('Content-Type: text/html; charset=utf-8'); but also you need to convert user inputed text to utf-8 in this case you will have no problem... I had the same problem with Armenian...

3
  • I've put header('Content-Type: text/html; charset=utf-8'); in sendform.php - it didn't work. All people I talk to suggest the same (headers, utf-8), but I don't know why it isn't working. By the way the contact.php needs to have the <meta charset="ISO-8859-1"> or it will not show any latin characters on the contact page form. Contact.php page is good, I only have a problem with sendform.php (sending emails I receive them with the funny characters).
    – user1220518
    Jun 14, 2012 at 21:48
  • it is more better to convert only the user input to utf-8: after word add it in an html file witch header <meta charset="utf-8"> and aferwords save the wholl page in a string and give it as an email content...
    – encoder
    Jun 14, 2012 at 22:10
  • you also will need to change the file encription in your IDE... if you tell me what IDE you are using I will be able to help you... after this step it will work normally
    – encoder
    Jun 19, 2012 at 14:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.