[PHP] utf-8 Umlaute Problem

Dieses Thema im Forum "Webentwicklung" wurde erstellt von DavyDave, 17. Juni 2010 .

Schlagworte:
Status des Themas:
Es sind keine weiteren Antworten möglich.
  1. 17. Juni 2010
    utf-8 Umlaute Problem

    Hey,
    irgendwie komm ich einfach nicht dahinter, wahrscheinlich ist das nur eine Kleinigkeit, aber mein PHP ist gerade nicht so berauschend.
    Jedenfalls hab ich dieses Script hier ein wenig angepasst.

    Das Problem ist bei dem versendeten Mails, die POSTs werden richtig dargestellt, sprich öäüß.
    Hingegen die Sachen die schon drinstehen wie "Qualität" , "Stückzahl" kommt in der Mail so raus: "Qualitt", "Stckzahl".

    Weiß jemand da eine Lösung?

    Spoiler
    PHP:
    <? php
    //Datum
    $name_tag [ 0 ] =  "Sonntag" ;
    $name_tag [ 1 ] =  "Montag" ;
    $name_tag [ 2 ] =  "Dienstag" ;
    $name_tag [ 3 ] =  "Mittwoch" ;
    $name_tag [ 4 ] =  "Donnerstag" ;
    $name_tag [ 5 ] =  "Freitag" ;
    $name_tag [ 6 ] =  "Samstag" ;
    $num_tag    date "w" );
    $day       $name_tag [ $num_tag ];
    $year       date ( "Y" );
    $day_num    date ( "d" );
    $month       date ( "m" );
    $time       = ( date ( "H:i" ));

    //        Who you want to recieve the emails from the form. (Hint: generally you.)
    $sendto  '*@*.de' ;
    $email  $_POST [ email ];

    //        The subject you'll see in your inbox
    $subject  '*.de | Kundenanfrage' ;
    $subject2  '*.de | Danke das Sie das Kontaktformular ausgefüllt haben' ;

    //        Message for the user when he/she doesn't fill in the form correctly.
    $errormessage  'Etwas stimmt noch nicht...' ;

    //        Message for the user when he/she fills in the form correctly.
    $thanks  "<strong>Vielen Dank f&uuml;r die Email, wir melden uns schnellst m&ouml;glich bei Ihnen!</strong>" ;

    //        Message for the bot when it fills in in at all.
    $honeypot  "You filled in the honeypot! If you're human, try again!" ;

    //        Various messages displayed when the fields are empty.
    $emptyname  =   'Fehlt Ihr Name?' ;
    $emptyemail  'Stimmt Ihre Emailadresse?' ;
    $emptymessage  'Haben Sie Ihre Nachricht eingegeben?' ;

    //       Various messages displayed when the fields are incorrectly formatted.
    $alertname  =   'Bitte geben Sie bei Ihrem Namen nur Zeichen des Standard Alphabets ein!' ;
    $alertemail  'Bitte E-Mailadresse in diesem Format: <i>name@beispiel.de</i>.' ;
    $alertmessage  "Bitte Nachricht nur als unformtierter Text!" ;

    //Setting used variables.
    $alert  '' ;
    $pass  0 ;

    // Sanitizing the data, kind of done via error messages first. Twice is better!
    function  clean_var ( $variable ) {
        
    $variable  strip_tags ( stripslashes ( trim ( rtrim ( $variable ))));
      return 
    $variable ;
    }

    //The first if for honeypot.
    if ( empty( $_REQUEST [ 'last' ]) ) {

        
    // A bunch of if's for all the fields and the error messages.
        
    if ( empty( $_REQUEST [ 'lname' ]) ) {
            
    $pass  1 ;
            
    $alert  .=  "" ;
        } elseif ( 
    ereg "[][{}()*+?.\\^$|]" $_REQUEST [ 'lname' ] ) ) {
            
    $pass  1 ;
            
    $alert  .=  "" ;
        }
        if ( empty(
    $_REQUEST [ 'firma' ]) ) {
            
    $pass  1 ;
            
    $alert  .=  "" ;
        } elseif ( 
    ereg "[][{}()*+?.\\^$|]" $_REQUEST [ 'firma' ] ) ) {
            
    $pass  1 ;
            
    $alert  .=  "" ;
        }
        if ( empty(
    $_REQUEST [ 'phone' ]) ) {
            
    $pass  1 ;
            
    $alert  .=  "" ;
        } elseif ( 
    ereg "[][{}()*+?.\\^$|]" $_REQUEST [ 'phone' ] ) ) {
            
    $pass  1 ;
            
    $alert  .=  "" ;
        }
        if ( empty(
    $_REQUEST [ 'email' ]) ) {
            
    $pass  1 ;
            
    $alert  .=  "" ;
        } elseif ( !
    eregi ( "^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,3})$" $_REQUEST [ 'email' ]) ) {
            
    $pass  1 ;
            
    $alert  .=  "" ;
        }

        
    //If the user err'd, print the error messages.
        
    if (  $pass == ) {

            
    //This first line is for ajax/javascript, comment it or delete it if this isn't your cup o' tea.
        
    echo  "<script>$(\".message\").hide(\"slow\").show(\"slow\"); </script>" ;
        echo 
    "" ;
        echo 
    "<ul>" ;
        echo 
    $alert ;
        echo 
    "</ul>" ;

        
    // If the user didn't err and there is in fact a message, time to email it.
        
    } elseif (isset( $_REQUEST [ 'message' ])) {
            
    //Construct the message.

    $message  "Nachricht gesendet am  $day $day_num . $month . $year  um  $time
                
    Daten:
    --------------------------------
    Abmessung: 
    $_POST [ abmessung ]
    Material: 
    $_POST [ material ]
    Qualität: 
    $_POST [ quality ]
    Stückzahl: 
    $_POST [ count ]
                
    Anschrift:
    --------------------------------
    $_POST [ firma ]
    $_POST [ anrede ] $_POST [ name ]   $_POST [ lname ]
    $_POST [ strasse ]
    $_POST [ plz ]   $_POST [ ort ]

    Tel. 
    $_POST [ phone ]
    E-Mail: 
    $_POST [ email ]
    --------------------------------

    Nachricht:
    --------------------------------
    $_POST [ message ]

    --------------------------------

            "
    ;
    $mail_body  utf8_decode ( $mail_body );
    $message2  "Am  $day $day_num . $month . $year  um  $time  haben wir folgende Nachricht von Ihnen erhalten:
                
    Daten:
    --------------------------------
    Abmessung: 
    $_POST [ abmessung ]
    Material: 
    $_POST [ material ]
    Qualität: 
    $_POST [ quality ]
    Stückzahl: 
    $_POST [ count ]

    Anschrift:
    --------------------------------
    $_POST [ firma ]
    $_POST [ anrede ] $_POST [ name ]   $_POST [ lname ]
    $_POST [ strasse ]
    $_POST [ plz ]   $_POST [ ort ]

    Tel. 
    $_POST [ phone ]
    E-Mail: 
    $_POST [ email ]

    --------------------------------

    Nachricht:
    --------------------------------
    $_POST [ message ]

    --------------------------------

    Ihre Mail wird so schnell wie möglich bearbeitet.

            "
    ;
            
    $header  "MIME-Version: 1.0\n" ;
    $header  .=  "Content-type: text/plain; charset=utf-8\n"
    $header  .=  "From: Kundenanfrage <*@*.de>\n" ;


    $header2  "MIME-Version: 1.0\n" ;
    $header2  .=  "Content-type: text/plain; charset=utf-8\n"
    $header2  .=  "From: Bestätigungsmail | *.de <*@*.de>\n"

    //Mail the message - for production
            
    mail ( $sendto $subject $message $header );
            
    mail ( $email $subject2 $message2 $header2 );
    //This is for javascript, 
            
    echo  "<script>$(\".message\").hide(\"slow\").show(\"slow\").animate({opacity: 1.0}, 4000).hide(\"slow\"); $(':input').clearForm() </script>" ;
            echo 
    $thanks ;

            die();

    //Echo the email message - for development
            //echo "<br/><br/>" . $message;

        
    }
        
    //If honeypot is filled, trigger the message that bot likely won't see.
    } else {
        echo 
    "<script>$(\".message\").hide(\"slow\").show(\"slow\"); </script>" ;
        echo 
    $honeypot ;
    }
    ?>
     
  2. 17. Juni 2010
    AW: utf-8 Umlaute Problem

    Wieso musses UTF-8 sein ?!
    Nimm doch ISO-8859-1 anstatt UTF-8..
    Denn sollte es auch mit den Umlauten etc funzen..

    Denn in UTF-8 kannst du meines wissens nach nur Umlaute mit &uuml; für zB ein ü nutzen.. Zumindest bei HTML...

    Hab hier noch was gefunden:
    Umlaut – Wikipedia

    MfG
     
  3. 17. Juni 2010
    AW: utf-8 Umlaute Problem

    1. Die PHP Datei mit einem Unicodefähigen Editor abspeichern (Notepad++ z.B.: Kodierung -> UTF8).
    2. phpMailer verwenden (und zwar immer!) - rumgewurschtel mit Headern führt fast immer zu Problem bei verschiedenen Mailanbietern.
     
  4. 17. Juni 2010
    AW: utf-8 Umlaute Problem

    Wenn ich ISO nehme dann sieht es wie folgt aus:

    äüöÃ? = aöäüß

    Sprich dann stimmt es wieder anders herum nicht.

    Mit den Hexadezimalen geht es auch nicht

    Edit: Kann da am Server nicht viel machen, sprich ich muss mit dem normalen php mail auskommen..
     
  5. 17. Juni 2010
    AW: utf-8 Umlaute Problem

    im grunde hat hier keiner ahnung wenn man sich die postings anschaut ^^

    wirklich ...

    php-files und utf-8 = fail. der parser kann utf-8 files nicht richtig verarbeiten.

    -----

    die lösung: mb_convert_encoding
     
  6. 17. Juni 2010
    AW: utf-8 Umlaute Problem

    Ist auch irgendwie nicht die Lösung, oder ich setzte es falsch ein:

    $message = mb_convert_encoding($message, "utf-8");
    $message2 = mb_convert_encoding($message2, "iso-8859-1");

    message
    Abmessung: äüö�
    Material: äüö�
    Qualität: äüöÃ?
    Stückzahl: 123

    message2
    Abmessung: äüöß
    Material: äüöß
    Qualitt: äüöß
    Stckzahl: 123
     
  7. 17. Juni 2010
    AW: utf-8 Umlaute Problem

    nein, du musst beides ins selbe format bringen.

    PHP:
    <? php

    $nachricht 
    mb_convert_encoding ( 'ÄÖÜßäöü: ' 'UTF-8' ) .  $_POST [ 'feld' ];
    z.b.

    d.h. alles zu utf-8 konvertieren.
    am besten du speicherst die nachricht separat in ner datei ab die du mit utf-8 konvertierst.
    dann mit nem platzhalter-prinzip die variablen einbauen.

    php solltest du nicht verwenden, da der php-parser utf-8 files nicht richtig verarbeiten kann.
     
  8. 17. Juni 2010
    AW: utf-8 Umlaute Problem

    Ja, hab ich gerade auch gemerkt Dankeschön.

    Hab das jetzt so:

    PHP:
    $_POST [ 'abmessung' ] =  utf8_decode ( $_POST [ 'abmessung' ]);
    $_POST [ 'material' ] =  utf8_decode ( $_POST [ 'material' ]);
    $_POST [ 'quality' ] =  utf8_decode ( $_POST [ 'quality' ]);
    $_POST [ 'count' ] =  utf8_decode ( $_POST [ 'count' ]);
    $_POST [ 'firma' ] =  utf8_decode ( $_POST [ 'firma' ]);
    $_POST [ 'anrede' ] =  utf8_decode ( $_POST [ 'anrede' ]);
    $_POST [ 'name' ] =  utf8_decode ( $_POST [ 'name' ]);
    $_POST [ 'lname' ] =  utf8_decode ( $_POST [ 'lname' ]);
    $_POST [ 'strasse' ] =  utf8_decode ( $_POST [ 'strasse' ]);
    $_POST [ 'plz' ] =  utf8_decode ( $_POST [ 'plz' ]);
    $_POST [ 'ort' ] =  utf8_decode ( $_POST [ 'ort' ]);
    $_POST [ 'phone' ] =  utf8_decode ( $_POST [ 'phone' ]); 
    $_POST [ 'email' ] =  utf8_decode ( $_POST [ 'email' ]);
    $_POST [ 'message' ] =  utf8_decode ( $_POST [ 'message' ]);
    $_POST [ 'anzahl' ] =  utf8_decode ( $_POST [ 'anzahl' ]);

    $message  mb_convert_encoding ( $message "utf-8" );
    $message2  mb_convert_encoding ( $message2 "utf-8" );
    Besser kann ich das nicht ^^ aber so lang es funktioniert.

    Das ist eh so, das die sendmail.php via AJAX dann geladen wird.
     
  9. 17. Juni 2010
    AW: utf-8 Umlaute Problem

    utf8_decode konvertiert aber zu iso-8859-1. alle unicode-sonderzeichen gehen verloren.
    wenn dus später wieder zu utf-8 konvertierst werden nur sonderzeichen zu utf-8 umgewandelt die auch in iso-8859-1 zur verfügung stehen.

    utf-8 über ajax, da haben wir es ja. das funktioniert nicht richtig
    verwende prototype und Form.request(), da geht es problemlos.
     
  10. 17. Juni 2010
    AW: utf-8 Umlaute Problem

    Okay. Ja das läuft jetzt erstmal, so lang wie ich an dem Scheiß hock reicht das so ^^

    Aber ich werd mir das nun fürs nächste mal merken (=
    Somit noch mal Danke.

    Closed.
     
  11. Video Script

    Videos zum Themenbereich

    * gefundene Videos auf YouTube, anhand der Überschrift.