Kontaktformular Umlaute

Nusskati

Mitglied
Hallo, in einem Wordpress-Style ist ein Kontaktformular integriert, leider werden bei den übertragenen Emails die Umlaute dann falsch dargestellt.
Beispiel:
herzlichen Glückwunsch,
Schöne
Ostern
Gruß Steffi

Dies ist der Code zu dem Kontaktformular:
PHP:
<?php
/*
Template Name: Contact
*/
?>
<?php

$nameError = '';
$emailError = '';
$commentError = '';

if(isset($_POST['submitted'])) {
        if(trim($_POST['contactName']) === '') {
                $nameError = true;
                $hasError = true;
        } else {
                $name = trim($_POST['contactName']);
        }

        if(trim($_POST['email']) === '')  {
                $emailError = true;
                $hasError = true;
        } else if (!eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}$", trim($_POST['email']))) {
                $emailError = 'You entered an invalid email address.';
                $hasError = true;
        } else {
                $email = trim($_POST['email']);
        }

        if(trim($_POST['comments']) === '') {
                $commentError = true;
                $hasError = true;
        } else {
                if(function_exists('stripslashes')) {
                        $comments = stripslashes(trim($_POST['comments']));
                } else {
                        $comments = trim($_POST['comments']);
                }
        }

        if(!isset($hasError)) {
                $emailTo = of_get_option('email_adress');
                if (!isset($emailTo) || ($emailTo == '') ){
                        $emailTo = of_get_option('gg_email_adress');
                }
                $subject = of_get_option('gg_email_subject');
                $body = "Name: $name \n\nEmail: $email \n\nComments: $comments";
                $headers = 'From: '.$name.' <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $email;

                mail($emailTo, $subject, $body, $headers);
                $emailSent = true;
        }
} ?>

<?php get_header(); ?>
               
                <div class="box-nm">
               
                <h1 class="pagetitle text-center"> <?php the_title(); ?> </h1>
               
                <div class="page-content">

                    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>                                   
   
                          <div class="contact">
                           
                                    <?php if(isset($emailSent) && $emailSent == true) { ?>
                                            <div class="thanks">
                                                    <p><?php _e('Thanks, your email was sent successfully.', 'gxg_textdomain') ?></p>
                                            </div>
                                    <?php } else { ?>
                                            <?php the_content(); ?>
                                            <?php if(isset($hasError) || isset($captchaError)) { ?>
                                                    <p class="error"><?php _e('Uh oh... an error occured.', 'gxg_textdomain') ?><p>
                                            <?php } ?>
   
                                    <form action="<?php the_permalink(); ?>" id="contactform" method="post">
                                    <fieldset>
                                            <ul>
                                                    <li>
                                                            <input type="text" name="contactName" id="contactName" value="<?php if(isset($_POST['contactName'])) echo $_POST['contactName'];?>"   class="required requiredField" />
                                                            <label for="contactName"><?php _e('Name', 'gxg_textdomain') ?></label>
                                                            <?php if($nameError != '') { ?>
                                                                    <div class="error"><?php _e('&larr; Please enter your name.', 'gxg_textdomain') ?></div>
                                                            <?php } ?>
                                                    </li>
   
                                                    <li>
                                                            <input type="text" name="email" id="email"  value="<?php if(isset($_POST['email']))  echo $_POST['email'];?>"  class="required requiredField email" />
                                                            <label for="email"><?php _e('Email', 'gxg_textdomain') ?></label>
                                                            <?php if($emailError != '') { ?>
                                                                    <div class="error"><?php _e('&larr; Please enter a valid email address.', 'gxg_textdomain') ?></div>
                                                            <?php } ?>
                                                    </li>
   
                                                    <li>
                                                            <textarea name="comments" id="commentsText" rows="12" class="required requiredField"><?php if(isset($_POST['comments'])) { if(function_exists('stripslashes')) { echo stripslashes($_POST['comments']); } else { echo $_POST['comments']; } } ?></textarea>
                                                            <label for="commentsText"><?php _e('Message', 'gxg_textdomain') ?></label>
                                                            <?php if($commentError != '') { ?>
                                                                    <div class="error"><?php _e('&larr; Please enter a message.', 'gxg_textdomain') ?></div>
                                                            <?php } ?>
                                                    </li>
   
                                                    <li>
                                                            <input id="submitmail" class="button1" type="submit" value="<?php _e('Send', 'gxg_textdomain') ?>" />
                                                    </li>
                                            </ul>
                                            <input type="hidden" name="submitted" id="submitted" value="true" />
                                     </fieldset>
                                     </form>
                                     <?php } ?>
                                    
                            </div><!-- .contact -->
   
                    <?php endwhile; endif; ?>

        </div> <!-- .page-content -->

                </div> <!-- .box-nm -->
                <?php  if ( is_active_sidebar( 'contact_sidebar' ) ) :  ?>
                <div class="m-container js-masonry widget-area centered">
                     <?php dynamic_sidebar( 'contact_sidebar' ); ?>
                </div><!-- .widget-area -->
                <?php endif; ?>

<?php get_footer(); ?>

Was fehlt da, damit in den Emails die Umlaute richtig angezeigt werden?
Ich habe schon im Internet gesucht, meist scheint die Lösung sehr einfach zu sein, leider hat davon aber noch nichts zu diesem Code gepasst.

Ich hoffe auf eure Hilfe und wünsche euch schöne Restostern :)
 
Mit was hat du es denn versucht? Hat du zum Beispiel deinen Inhalt ($comments) durch utf8_encode gejagt?
Wenn das nicht hilft, versuche doch mal herauszufinden, welche Codierung die Datei selbst hat. Eventuell musst du deinen Editor dahingehend umstellen, dass er UTF8-Dokumente speichert.

Lg Chris
 
Hi,

ohne jetzt viel zu überlegen, kann auch falsch sein, versuche das mal bei Zeile 48 bzw. ändere es mal ab

PHP:
$headers  .=  'From: '.$name.' <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $email;
$headers .= "Mime-Version: 1.0\r\n";
$headers .= "Content-type: text/plain; charset=iso-8859-1"
 
Hallo lockcat, danke für deine Antwort.
Dann sieht der Code so aus:
PHP:
        if(!isset($hasError)) {
                $emailTo = of_get_option('email_adress');
                if (!isset($emailTo) || ($emailTo == '') ){
                        $emailTo = of_get_option('gg_email_adress');
                }
                $subject = of_get_option('gg_email_subject');
                $body = "Name: $name \n\nEmail: $email \n\nComments: $comments";
                $headers  .=  'From: '.$name.' <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $email;
                $headers .= "Mime-Version: 1.0\r\n";
                $headers .= "Content-type: text/plain; charset=iso-8859-1"

                mail($emailTo, $subject, $body, $headers);
                $emailSent = true;
        }

Leider bekomme ich dann beim Aufrufen der Datei eine Fehlermeldung:
Parse error: syntax error, unexpected 'mail' (T_STRING) in /www/htdocs/w0140d38/template-contact.php on line 52

Zeile 52 ist die drittletzte Zeile.
 
Versuche das nochmal bitte hab das Semikolon in zeile 10 vergessen -.-*

PHP:
$headers .=  'From: '.$name.' <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $email;
$headers .= "Mime-Version: 1.0\r\n";
$headers .= "Content-type: text/plain; charset=iso-8859-1";

Gruß
 
Okay die Daten, die versendet werden kommen die aus einer Datenbank?
versuche dies doch mal bitte:

PHP:
$headers .=  'From: '.$name.' <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $email;
$headers .= "Mime-Version: 1.0\r\n";
$headers .="Content-Type: text/html; charset=UTF-8";
 

Neue Beiträge

Zurück