1

I have created a contact form, you can view it here. When I fill out the contact form and go to my inbox folder - the Norwegian letters æ, ø, å aren't shown in the message.

This is what I have currently added:

<meta http-equiv="content-type" content="text/html" charset="ISO-8859-1">

I have also tried <form accept-charset="ISO-8859-1">, but with no luck.

Here is a screenshot from the e-mail I receive after contact form has been submitted enter image description here as you can see there are no æ, ø, å letters.

Is there any way I can fix this?

PHP Code:

if (isset($_POST["submit"])) {
    $name = $_POST['name'];
    $email = $_POST['email'];
    $message = $_POST['message'];
    $number = $_POST['number'];
    $from = 'Ny melding sendt fra kontaktskjema på Helsespesialisten.no'; 
    $to = 'test@test'; 
    $subject = 'Helsespesialisten | Du har motatt en ny melding';

    $body = "Fra: $name\n E-post: $email\n Telefonnummer: $number\n Melding: $message\n";

    // Check if name has been entered
    if (!$_POST['name']) {
        $errName = 'Vennligst skriv inn ditt navn';
    }

    // Check if email has been entered and is valid
    if (!$_POST['email'] || !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
        $errEmail = 'Vennligst skriv inn din e-post';
    }

    //Check if message has been entered
    if (!$_POST['number']) {
        $errNumber = 'Vennligst skriv inn ditt telefonnummer';
    }


    //Check if message has been entered
    if (!$_POST['message']) {
        $errMessage = 'Vennligst skriv en melding';
    }

    // If there are no errors, send the email
    if (!$errName && !$errEmail && !$errNumber && !$errMessage) {
        if (mail ($to, $subject, $body, $from, $number)) {
            $result='<div class="alert alert-success">Takk for din henvendelse! Vi tar kontakt i løpet av kort tid!</div>';
        } else {
            $result='<div class="alert alert-danger">Beklager, en feil skjedde! Kontakt oss på: +47 35 11 15 40</div>';
        }
    }
}
P. Frank
  • 5,691
  • 6
  • 22
  • 50
NohmanJ
  • 167
  • 3
  • 15
  • 1
    try UTF-8 instead just as you tagged it. – Funk Forty Niner Oct 23 '15 at 12:32
  • @Fred-ii- I've tried that also – NohmanJ Oct 23 '15 at 12:32
  • 1
    is the file saved "as" UTF-8? – Funk Forty Niner Oct 23 '15 at 12:33
  • UTF8 is def the answer... – An0nC0d3r Oct 23 '15 at 12:35
  • Are you implementing both sides or just coding up the form to send. What is the email client you are reading it in? – An0nC0d3r Oct 23 '15 at 12:37
  • @Fred How can I check if the file is saved as UTF-8? – NohmanJ Oct 23 '15 at 12:37
  • Ive never experienced this myself, and im not using any charset. It might be dependant on the email application you use as well. – MrK Oct 23 '15 at 12:38
  • Use a code editor and see the file's encoding. I use Notepad++ myself. You will have a choice between UTF-8 with, or without BOM (byte order mark). Try both. – Funk Forty Niner Oct 23 '15 at 12:38
  • @AdamJeffers I'm using Mozilla Thunderbird, i'm implementing both I believe. I edited code with UTF-8, but still same problem – NohmanJ Oct 23 '15 at 12:44
  • @KristianHareland I'll check with Thunderbird, but usually when I write other e-mails the letters show up, so I think its somewhere in the coding i'm missing something. – NohmanJ Oct 23 '15 at 12:44
  • And changin to "" makes no difference? – An0nC0d3r Oct 23 '15 at 12:45
  • @AdamJeffers Correct. – NohmanJ Oct 23 '15 at 12:46
  • Whatever editor you're using, go to 'save with encoding' or something similar and try to save it as UTF-8... I use sublime – An0nC0d3r Oct 23 '15 at 12:47
  • this might be something you should look into: http://php.net/manual/en/function.utf8-encode.php – MrK Oct 23 '15 at 12:47
  • I checked encoding in Sublime and it says: UTF-8 – NohmanJ Oct 23 '15 at 12:47
  • Go through this http://stackoverflow.com/questions/279170/utf-8-all-the-way-through there may be additional information in there that you may not be doing. – Funk Forty Niner Oct 23 '15 at 12:49
  • Have you got the language pack installed on the machine you are reading the email on? – An0nC0d3r Oct 23 '15 at 12:49
  • He is norwegian based off his screenshot so i would guess he has it installed – MrK Oct 23 '15 at 12:50
  • Yes, language pack is installed. I write/receive norwegian emails everyday through Thunderbird without any problems, but when receiving email from contact-form, the letters don't show. – NohmanJ Oct 23 '15 at 12:53
  • Since you're not using any non-ascii characters **in your PHP source code**, it doesn't matter how your .php file is encoded. However your source code – RocketNuts Oct 23 '15 at 13:07
  • Did you try [this](http://stackoverflow.com/q/3624681/1336342)? – green Oct 23 '15 at 13:12
  • Ignore my previous comment, posted to early, I meant: if you're not using any non-ascii characters **in your PHP source code**, it doesn't matter how your .php file is encoded. However your php contains chars like å so then it matters (in that case, make sure it's utf-8). But what matters most is the encoding used and specified by your HTML, and that's already utf-8 due to your `http-equiv="content-type"` header. Forget about the `accept-charset` in your `
    ` tag, just make sure to interpret the submitted form data as utf-8 (since that's what your html also specifies), and you'll be fine.
    – RocketNuts Oct 23 '15 at 13:14

1 Answers1

1

Try this:

if (isset($_POST["submit"])) {
                        $name = $_POST['name'];
                        $email = $_POST['email'];
                        $message = $_POST['message'];
                        $number = $_POST['number'];
                        $from = 'Ny melding sendt fra kontaktskjema på Helsespesialisten.no'; 
                        $to = 'test@test'; 
                        $subject = 'Helsespesialisten | Du har motatt en ny melding';

                        $headerFields = array(
                            "From: $from",
                            "MIME-Version: 1.0",
                            "Content-Type: text/html;charset=utf-8"
                        );

                        $body = "Fra: $name\n E-post: $email\n Telefonnummer: $number\n Melding: $message\n";

                        // Check if name has been entered
                        if (!$_POST['name']) {
                            $errName = 'Vennligst skriv inn ditt navn';
                        }

                        // Check if email has been entered and is valid
                        if (!$_POST['email'] || !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
                            $errEmail = 'Vennligst skriv inn din e-post';
                        }

                        //Check if message has been entered
                        if (!$_POST['number']) {
                            $errNumber = 'Vennligst skriv inn ditt telefonnummer';
                        }


                        //Check if message has been entered
                        if (!$_POST['message']) {
                            $errMessage = 'Vennligst skriv en melding';
                        }

                // If there are no errors, send the email
                if (!$errName && !$errEmail && !$errNumber && !$errMessage) {
                    if (mail ($to, $subject, $body, implode("\r\n", $headerFields))) {
                        $result='<div class="alert alert-success">Takk for din henvendelse! Vi tar kontakt i løpet av kort tid!</div>';
                    } else {
                        $result='<div class="alert alert-danger">Beklager, en feil skjedde! Kontakt oss på: +47 35 11 15 40</div>';
                    }
                }
                    }
MrK
  • 1,060
  • 9
  • 23
  • I'm not so familiar with PHP, but I have added the current PHP I'm using in the post, are you able to help me update the code? (Tar det på engelsk, for at andre skal forstå, er ikke jeg som har skrevet PHP koden, men min partner :)) – NohmanJ Oct 23 '15 at 13:03
  • Edited answer :) @NohmanJ, legg meg gjerne til på faceB eller noe dersom du trenger mer hjelp :) – MrK Oct 23 '15 at 13:05
  • Worked perfect! Thanks! (Takker og bukker! :D ) – NohmanJ Oct 23 '15 at 13:11