斯堪的纳维亚信件以电子邮件形式

时间:2011-06-15 17:09:05

标签: php

我无法将斯堪的纳维亚字母ÆØÅ/æøå用于我的电子邮件表格。表单发送消息,我收到它就好了,除非消息中有ÆØÅ/æøå。

非常感谢任何帮助!

<?php
header('Content-type: text/html; charset=utf-8');
$header = "Content-type: text/plain; charset=utf-8\r\n";

session_start();
ob_start();
$dontsendemail = 0;
$possiblespam = FALSE;
$strlenmessage = "";
$email = $_POST['email']; 
$message = $_POST['message'];
$subject = $_POST['subject'];


$emailaddress = array();
$emailaddress[1] = "lalala@lalala.lala";
    $emailaddress[2] = "lalala@llllaaa.laaaa";
    $emailaddress[3] = "laaaverksted@laa.verksted";
    $emailaddress[4] = "ess@xfrag.com";
    $contactnameindex = $_POST['emailaddress'];
if ($contactnameindex == 0 || !isset($_POST['emailaddress'])) echo '<div id="notification" class="info_div"><span class="ico_cancel">Du valgte ikke en mottaker.</span></div>';
else $emailaddress = $emailaddress[$contactnameindex];
function checkcaptcha() {
        if ($_SESSION["pass"] != $_POST["userpass"]) {
            echo '<div id="notification" class="info_div"><span class="ico_cancel">Beklager, men feilet i å skrive inn bildeverifiseringen. Merk at bildeverifiseringen krever at du skiller imellom store og små bokstaver.</span></div>';
            return 1;
        }
    }

function checkemail($field) {
// checks proper syntax
if( !preg_match( "/^([a-zA-Z0-9])+([a-zA-Z0-9._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9._-]+)+$/", $field))
{
    echo '<div id="notification" class="info_div"><span class="ico_cancel">Feilaktig e-postadresse registrert.</span></div>'; 
    return 1;
}
}
function spamcheck($field) {
if(eregi("to:",$field) || eregi("cc:",$field) || eregi("\r",$field) || eregi("\n",$field) || eregi("%0A",$field)){ 
    $possiblespam = TRUE;
}else $possiblespam = FALSE;
if ($possiblespam) {
    echo '<div id="notification" class="info_div"><span class="ico_cancel">Mulig forsøk på spam oppdaget. Hvis dette ikke er tilfelle, kan du redigere innholdet i kontaktskjemaet, og prøv igjen.</span></div>';
    return 1;
}
}
function strlencheck($field,$minlength,$whichfieldresponse) {
if (strlen($field) < $minlength){
    die($whichfieldresponse); 
    return 1;
}
}

    if ($dontsendemail == 0) $dontsendemail = checkcaptcha($email);

if ($dontsendemail == 0) $dontsendemail = checkemail($email);
if ($dontsendemail == 0) $dontsendemail = spamcheck($email);
if ($dontsendemail == 0) $dontsendemail = spamcheck($subject);
if ($dontsendemail == 0) $dontsendemail = strlencheck($email,10,'<div id="notification" class="info_div"><span class="ico_cancel">E-mail feltet er for kort.</span></div>');

if ($dontsendemail == 0) $dontsendemail = strlencheck($subject,5,'<div id="notification" class="info_div"><span class="ico_cancel">Emnefeltet er for kort.</span></div>');

if ($dontsendemail == 0) $dontsendemail = strlencheck($message,10,'<div id="notification" class="info_div"><span class="ico_cancel">Meldingen er for kort.');
if ($dontsendemail == 0) $dontsendemail = strlencheck($emailaddress,8,'<div id="notification" class="info_div"><span class="ico_cancel">Du har ikke valgt en mottaker av meldingen.</span></div>');
if ($dontsendemail == 0){mail($emailaddress, "Emne: $subject","Fra: $email", $message); echo '<div id="sent" class="info_div"><span class="ico_success">Takk! Din e-post til oss er registrert og vil bli besvart innen 24-timer på dagene Mandag-Fredag.</span></div>'; }
ob_end_flush();
?>

3 个答案:

答案 0 :(得分:1)

您的邮件正文中没有指定内容的字符集。您在脚本顶部执行的header()调用不适用于电子邮件,它仅适用于发送到运行此脚本的浏览器的脚本输出。

由于它是HTML电子邮件,您必须将元标记放入邮件的<head>块中:

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

但是,请不要手动构建这样的MIME / html邮件。这太难看了。使用SwiftmailerPHPMailer自动完成所有繁重的工作。他们快速,轻松,自由。

答案 1 :(得分:0)

您是否忘记了浏览器编码?还有电子邮件客户端编码?

此外,您无法将数组发送到mail();功能 编辑:另外,你不应该使用eregi();因为它被弃用了

答案 2 :(得分:0)

由于历史原因,标准电子邮件编码为ISO-8859-1。

要正确发送您的字符,您必须将电子邮件显式编码为UTF-8,如下所示:PHP Send UTF-8 mail without PEAR::Mail PEAR::Mail_Mime

或者,您可以使用utf8_decode()将文本转换为ISO-8859-1。然而,这只适用于西方人物(= ISO-8859-1所涵盖的那些) - 使用UTF-8一直是很多更好的选择。