Php联系表单,如何使用charset utf-8发送?

时间:2014-03-06 14:31:05

标签: php html utf-8

我有以下php联系表单代码,它的工作完美,只是它没有发送charset UTF-8,我需要我的语言。

任何人都知道如何使用urf-8发送它?

提前致谢,杰克

<?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");
?>

1 个答案:

答案 0 :(得分:0)

尝试添加Content-Type标头。改变这一行:

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

致:

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

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

您可以找到here发送utf-8电子邮件的功能。