PHP-格式中的特殊字母?

PHP-格式中的特殊字母?,php,forms,character-encoding,Php,Forms,Character Encoding,我有一个工作联系表单,但我遇到了以下问题:该网站主要提供芬兰内容,表单不太喜欢斯堪的纳维亚字母(ä,ö,å)。电子邮件看起来都乱七八糟,直接发送到垃圾邮件。我尝试过更改HTML字符集,但没有任何效果 <html> <head> <meta http-equiv="Content-Type" content="text/html;charset=utf-8"> <title>Artotek - Yhteyden

我有一个工作联系表单,但我遇到了以下问题:该网站主要提供芬兰内容,表单不太喜欢斯堪的纳维亚字母(ä,ö,å)。电子邮件看起来都乱七八糟,直接发送到垃圾邮件。我尝试过更改HTML字符集,但没有任何效果

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

    <?php
    if(isset($_POST['email'])) {

        // EDIT THE 2 LINES BELOW AS REQUIRED
        $email_to = "artjom@europe.com";
        $email_subject = "**Yhteydenotto**"; 

        function died($error) {

            // your error code can go here
            echo "Olemme pahoillamme, mutta lomakkeestasi löytyi virhe(itä). ";
            echo "Alapuolella näet virheesi.<br /><br />";
            echo $error."<br /><br />";
            echo "Ole hyvä, ja mene takaisin korjaamaan nämä virheet, ja yritä uudelleen.<br /><br />";
            die();

        }

        // validation expected data exists
        if(!isset($_POST['first_name']) ||
            !isset($_POST['last_name']) ||
            !isset($_POST['email']) ||
            !isset($_POST['telephone']) ||
            !isset($_POST['comments'])) {
            died('Lomakkeessasi oli ongelmia');       
        }

        $first_name = $_POST['first_name']; // required
        $last_name = $_POST['last_name']; // required
        $email_from = $_POST['email']; // required
        $telephone = $_POST['telephone']; // not required
        $comments = $_POST['comments']; // required

        $error_message = "";
        $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
        if(!preg_match($email_exp,$email_from)) {
            $error_message .= 'Sähköpostiosoite ei ole käytössä.<br />';
        }

        $string_exp = "/^[A-Za-z .'-]+$/";
        if(!preg_match($string_exp,$first_name)) {
            $error_message .= 'Etunimesi ei näytä olevan oikea.<br />';
        }

        if(!preg_match($string_exp,$last_name)) {
            $error_message .= 'Sukunimesi ei näytä olevan oikea.<br />';
        }

        if(strlen($comments) < 2) {
            $error_message .= 'Viesti ei täytä vähimmäisvaatimuksia.<br />';
        }

        if(strlen($error_message) > 0) {
            died($error_message);
        }
        $email_message = "Lomaketiedot alla.\n\n";

        function clean_string($string) {
          $bad = array("content-type","bcc:","to:","cc:","href");
          return str_replace($bad,"",$string);
        }

        $email_message .= "Etunimi: ".clean_string($first_name)."\n";
        $email_message .= "Sukunimi: ".clean_string($last_name)."\n";
        $email_message .= "Sähköposti: ".clean_string($email_from)."\n";
        $email_message .= "Puhelinnumero: ".clean_string($telephone)."\n";
        $email_message .= "Viesti: ".clean_string($comments)."\n";

        //create email headers
        mail($email_to, $email_subject, $email_message, $headers, 'MIME-Version: 1.0' . "\r\n" . 'Content-type: text/plain; charset=UTF-8' . "\r\n");

        /*
        $headers = 'From: '.$email_from."\r\n".
        'Reply-To: '.$email_from."\r\n" .
        'X-Mailer: PHP/' . phpversion();
        @mail($email_to, $email_subject, $email_message, $headers); 
        //@mail($email_to2, $email_subject, $email_message, $headers);  
        */
    ?>
    <!-- include your own success html here -->
    <div style="text-align: center; background: lightgreen; top: 50%; position: absolute; left: 0%; box-shadow: gray 5px 3px  5px;">
    <font face="century gothic"><h1>Kiitos yhteydenotostasi. Otamme teihin yhteyttä; piakkoin.</h1>
    </div>
    <div style="position: absolute; top: 60%; right: 15%; text-align:center; background: red; width: 30%;">
    <a href="index.php" style="color:inherit; text-decoration: none;"><h2>Takaisin</h2></font>

    <?php

    }

    ?>

阿托泰克-伊泰德诺托
基托斯yhteydenotostasi。Otamme teihin yhteyttä;piakkoin。
高信

我建议你选择一个像“swiftmailer”这样的库,而不是尝试自己用mail编写邮件

这将处理字符集问题,以及在多部分邮件上设置边界等,以减少您点击垃圾邮件过滤器的机会

“邮件”听起来是一个简单的解决方案,但只要你想使用ASCII格式的纯文本邮件以外的任何东西,那就太麻烦了。

1)首先,你可能想检查文件的真实文件编码,上面的字符集并不意味着你的文件是这样编码的

2) 使用像swift mailer、zend mail或PHPMailer这样经过测试的邮件库来发送电子邮件,除了发送简单的基于文本的ASCII电子邮件外,我不知道有多少硬核开发人员尝试使用“mail()”发送邮件,他们都使用库


3) 使用电子邮件测试/预览应用程序确保您的电子邮件在所有客户机中正确发送。我曾经在试图找出我的邮件看起来不好的原因时损失了6小时,现在我用一个我不记得名字的工具,我发现它只在我的客户身上是坏的,其他人都很好。。。它给了我完成它所需要的提示,因为我知道我在寻找一个特定的问题,而不是一个大问题

听起来像我:)只是。。。快点!没错,还有很多其他选择。但是请相信我(和@mathieu dumoulin),建立这样一个库远没有尝试运行自己的邮件函数那么复杂。你的
clean_string
函数没有任何意义。看起来您在阻止标头注入方面做得很糟糕,但您根本没有将其应用于标头。我在internet上找到了该示例。我自己知道的很少。