联系表格特殊字符

时间:2017-03-13 11:30:40

标签: php html contact-form

我在使用验证码时遇到问题。 它根本不会显示像äöüß这样的特殊角色。 现在它以某种方式在发送时删除它们。 联系表格在http://interdomo.de/kontakt/kontaktformular.php在线 我已经在(页面和表单)

中添加了UTF-8字符集

以下是联系表单的php脚本:

        $from="";
    $anbebot="";

    $name="";
    $email="";
    $nachricht="";
    $check_1=0;
    $check_2=0;
    $check_3=0;
    $fehler=0;
    $email_fehler=0;
    $nachricht_fehler=0;
    $captcha_fehler=0;

        if( isset($_GET["from"]) && ( $_GET["from"]=="Buchhaltung" || $_GET["from"]=="Autohausberatung" ) ){ $from=$_GET["from"]; }
        if( isset($_GET["angebot"]) && $_GET["angebot"]==1 ){$check_1=1;}
        if( isset($_GET["angebot"]) && $_GET["angebot"]==2 ){$check_2=1;}
        if( isset($_GET["angebot"]) && $_GET["angebot"]==3 ){$check_3=1;}



        if (isset($_POST["submit"])){
            function repl($vari){
            $vari = trim(preg_replace("/[^A-Z a-z 0-9 ÄÖÜäöüß \\n\\r@&€;\/\(\)-=~.,;:*|#\"\'\/?!%]/", " ", $vari));
            return $vari;
            }

            $name= repl($_POST["name"]);
            $email= repl($_POST["email"]);
            if (!preg_match('/^[0-9A-Za-zÄÖÜÄÖÜß ]([-_.]?[0-9A-Za-zÄÖÜäöüß])*@[0-9A-Za-zÄÖÜäöüß]([-.]?[0-9A-Za-zÄÖÜäöüß])*\\.[a-z]{2,4}$/',$email) ){
            $fehler=1;$email_fehler=1;
            }
            $nachricht= repl($_POST["nachricht"]);
            if (strlen($nachricht)<=8){$fehler=1;$nachricht_fehler=1;}

            if (isset($_SESSION['captcha_spam']) && $_POST["sicherheitscode"] <> $_SESSION['captcha_spam']){
            $fehler=1;$captcha_fehler=1;
            }

            if( isset($_POST["check_1"]) && $_POST["check_1"]==1 ){$check_1=1;}
            if( isset($_POST["check_2"]) && $_POST["check_2"]==1 ){$check_2=1;}
            if( isset($_POST["check_3"]) && $_POST["check_3"]==1 ){$check_3=1;}

            if( isset($_POST["from"]) && ( $_POST["from"]=="Buchhaltung" || $_POST["from"]=="Autohausberatung" ) ){ $from=$_POST["from"]; }

        }

        if (isset($_POST["submit"]) && $fehler<>1 && isset($_SESSION['captcha_spam']) && $_POST["sicherheitscode"] == $_SESSION['captcha_spam']){
        unset($_SESSION['captcha_spam']);


        $zeit=date("H:i");
        $datum=date("d.m.Y");
        $mailtext="Anfrage vom $datum um $zeit Uhr\n";
        if (isset($from) && ($from=="Buchhaltung" || $from=="Autohausberatung" ) ){
        $mailtext.="\n----------------------------------\n";
        $mailtext.="Anfrage zu: $from";
        }
        $mailtext.="\n----------------------------------\n\n";

        if ( $check_1==1 || $check_2==1 || $check_3==1  ){
            $mailtext.="Ich bin an folgendem/n Angebot/en interessiert:\n";
            if($check_1==1){$mailtext.=" - individuelles Angebot erstellen\n";}
            if($check_2==1){$mailtext.=" - Festpreisangebot anfordern\n";}
            if($check_3==1){$mailtext.=" - kostenlose Kurzanalyse anfordern\n";}
            $mailtext.="\n";
        }


        $mailtext.="Name: $name\n";
        $mailtext.="E-Mail: $email\n\n";

        $mailtext.="Nachricht:\n";
        $mailtext.="$nachricht\n";
        $email = trim(preg_replace( "/(content-type:|bcc:|cc:|to:|from:)/im", "", $email ));
        $mailtext = trim(preg_replace( "/(content-type:|bcc:|cc:|to:|from:)/im", "", $mailtext ));

        $mailheaders = "From:$email";



        //echo("<pre>$mailtext</pre>");
        mail("email@email.com","Kontaktformular",$mailtext,$mailheaders);


        echo("<div id='response'>Vielen Dank f&uuml;r Ihre Anfrage.<br>Wir werden uns so schnell wie m&ouml;glich um Ihr Anliegen k&uuml;mmern.</div>");

        }

我现在还要在这里添加html代码:

<form method="post" action="kontaktformular.php#response" accept-charset="UTF-8">
  <input type="hidden" name="from" value="<?php echo($from); ?>" />
    <legend>
    <h2>Ich bin an folgendem/n Angebot/en interessiert:</h2>
    </legend>

    <div class="form-group">
    <input type="checkbox" name="check_1" value="1" <?php if($check_1==1){echo("checked='checked'");} ?> /> individuelles Angebot erstellen<br />
    </div>

    <div class="form-group">
    <input type="checkbox" name="check_2" value="1" <?php if($check_2==1){echo("checked='checked'");} ?> /> Festpreisangebot anfordern<br />
    </div>

    <div class="form-group">
    <input type="checkbox" name="check_3" value="1" <?php if($check_3==1){echo("checked='checked'");} ?> /> kostenlose Kurzanalyse anfordern<br /><br />
    </div>

    <div class="form-group">
    <label>Name:</label>
    <input type="text" name="name" value="<?= $name; ?>" class="form-control">
    </div>

    <div class="form-group">
    <label>E-Mail:</label>
    <input type="text" name="email" value="<?= $email; ?>" class="form-control"  style="<? if ($email_fehler==1){echo("border:1px solid #ff0000;");}else{echo("border:1px solid #999999;");} ?> background-color:#eeeeee;">
    </div>

    <div class="form-group">
    <label>Ihre Nachricht:</label>
    <textarea name="nachricht" rows="5" class="form-control" style=" <? if ($nachricht_fehler==1){echo("border:1px solid #ff0000;");}else{echo("border:1px solid #999999;");} ?> background-color:#eeeeee;"><? echo stripslashes($nachricht); ?></textarea>
    </div>

    <div class="form-group">
    Sicherheitscode:
    <table class="table">
                <tr>
                  <td><img src="../captcha/captcha.php" border="0" title="Sicherheitscode" style="padding-bottom:6px; padding-right:6px;"></td>
                  <td>Bitte geben Sie hier den  Sicherheitscode ein.</td>
                </tr>
            </table>
    </div>

    <div class="form-group">
        <input type="text" name="sicherheitscode" size="5" class="form-control" style="<? if ($captcha_fehler==1){echo("border:1px solid #ff0000;");}else{echo("border:1px solid #999999;");} ?>">
    </div>


    <div class="form-group">
        <input type="Submit" name="submit" class="sendbutton" onMouseOver="this.style.cursor='pointer';" value="Nachricht senden" style="border:1px solid #999999; width: 200px;">
    </div>

</form>

1 个答案:

答案 0 :(得分:0)

问题在于php文件的格式。 它是用一个旧程序构建的,并设置为ANSI,我用notepad ++打开代码并将其保存为utf-8并且一切正常。

相关问题