0

I have the following php contact form code and it's working perfect except that it isn't sending with charset UTF-8, which I need for my language.

Anyone know how to make it send with urf-8?

Thanks in advance, Jack

<?php
$error    = ''; // error message
$name     = ''; // sender's name
$email    = ''; // sender's email address
$subject  = ''; // subject
$message  = ''; // the message itself
$spamcheck = ''; // Spam check
$telefon = ''; // telefon
$kategori = ''; // kategori

if(isset($_POST['send']))
{
$name     = $_POST['name'];
$email    = $_POST['email'];
$subject  = $_POST['subject'];
$message  = $_POST['message'];
$spamcheck = $_POST['spamcheck'];
$telefon = $_POST['telefon'];
$kategori = $_POST['kategori'];

if(trim($name) == '')
{ $error = '<div class="errormsg">Skriv in ditt namn.</div>'; }
else if(trim($email) == '')
{ $error = '<div class="errormsg">Skriv in din e-mail adress.</div>'; }
else if(!isEmail($email))
{ $error = '<div class="errormsg">Du har skrivit in en ogiltig e-mail adress. Försök igen!</div>'; }
if(trim($subject) == '')
{ $error = '<div class="errormsg">Skriv in ett ämne.</div>'; }
else if(trim($message) == '')
{ $error = '<div class="errormsg">Skriv in ditt meddelande.</div>'; }
else if(trim($spamcheck) == '')
{ $error = '<div class="errormsg">Svara på Antispam frågan!</div>'; }
else if(trim($spamcheck) != '5')
{ $error = '<div class="errormsg">Antispam: Felaktigt svar! 2 + 3 = ?</div>';}

if($error == '')
{
if(get_magic_quotes_gpc())
{ $message = stripslashes($message); }

// the email will be sent here
// make sure to change this to be your e-mail
$to      = "";

$subject = '[Sigster] : ' . $subject;

// the mail message ( add any additional information if you want )
$msg     = "Från : $name \r\nE-Mail : $email \r\nTelefon : $telefon \r\nKontakta mig genom : $kategori \r\nÄmne : $subject \r\n\n" . "Meddelande : \r\n$message";

mail($to, $subject, $msg, "From: $email\r\nReply-To: $email\r\nReturn-Path: $email\r\n");
?>
Jack
  • 245
  • 1
  • 5
  • 11

1 Answers1

0

Try to add the Content-Type header. Change the line :

mail($to, $subject, $msg, "From: $email\r\nReply-To: $email\r\nReturn-Path: $email\r\n");

To :

$headers = array
(
    'Content-Type: text/html; charset="UTF-8";',
    'From: ' . $email,
    'Reply-To: ' . $email,
    'Return-Path: ' . $email,
);

mail($to, $subject, $msg, implode("\n", $headers));

You can find here a function to send utf-8 email.

ncrocfer
  • 2,542
  • 4
  • 33
  • 38