0

So I have made a contact form on my website. Everything works like a charm. However, the result beeing delivered to the email fail to display the ØÆÅ letters and instead only shows as weird symbols.. I have tried everything and feel really lost.

<?php 

if (isset($_POST['submit']))
$sword = $_POST['swordy'];
$check = $_POST['check']; 
$mailFrom = $_POST['mail'];
$message = $_POST['message'];
$ccname = $_POST['ccname'];
$droppy1 = $_POST['droppy1'];
$tel = $_POST['tel'];
$subject = 'Bryllupsinvitasjon ';

$mailTo = "your@email.com";
$headers = "From: ".$mailFrom;
$txt = " Du har motatt svar på bryllupsinvitasjon fra: ".$ccname."\n\n Svar: $check \n\n Telefonnummer: $tel\n\n Allergier: $droppy1\n\n Andre allergier/intolleranser/spørsmål/henvendelser: $message";    

mail($mailTo, $subject, $txt, $headers);
header("Location: index.html?mailsendt"); 
?>
Cosmochen
  • 61
  • 6
  • You need to set and consequently use the same encoding throughout your website. A common one is UTF-8. –  Feb 11 '19 at 19:40
  • I use UTF-8 all over the website. – Cosmochen Feb 11 '19 at 19:49
  • Take a look at https://stackoverflow.com/a/27648245/1535270 . It shows how to fix the body of your message and headers, specifying their encoding. – abestrad Feb 11 '19 at 21:31

2 Answers2

0

Try inserting the corresponding Unicode or HTML code for your specific character. I believe all three of your indicated chars are on this page: https://www.rapidtables.com/code/text/unicode-characters.html

Russ J
  • 828
  • 5
  • 12
  • 24
0

Your email headers here aren't specifying UTF-8 encoding. You'll need to add that into the headers, specifically as part of the Content-Type header, like so:

Content-Type: text/html; charset="UTF-8"

With that header, the email should display the characters properly.

IceMetalPunk
  • 5,476
  • 3
  • 19
  • 26
  • Sorry, I´m really a rookie on this... How exactly do I do this? Don´t know how to change the header like to explain :/ – Cosmochen Feb 11 '19 at 20:49
  • Your code currently sets the headers in this variable: `$headers = "From: ".$mailFrom;` Headers in emails are separated by line breaks, `\r\n`. So you can just add another, making the entire line: `$headers = "From: ".$mailFrom."\r\nContent-Type: text/html; charset=\"UTF-8\"";` – IceMetalPunk Feb 11 '19 at 21:06
  • It looks really good, but with that in the emails wont show up in the inbox. It worked one time and after that it just stopped showing up. That one time still had the problem with the symbols aswell :/ – Cosmochen Feb 11 '19 at 21:22