Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8

Thread: Help with UTF-8

  1. #1
    New Coder
    Join Date
    Dec 2011
    Posts
    35
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Help with UTF-8

    Hi guys and sorry if this has been up before.
    I've googled it and found some answers, but non of them has helped me out.

    I have a simple php mail form, but all of the mails are wrong since i'm missing the "special caracters" ÅÄÖ
    So i need the form to be sent as UTF-8.

    I'm novice, so take it easy on me

    PHP Code:
    <?php 
    $errors 
    '';
    $myemail 'xxx@minmail.com';
    if(empty(
    $_POST['datum'])  || 
       empty(
    $_POST['name'])  || 
       empty(
    $_POST['tele']) || 
       empty(
    $_POST['email']) || 
       empty(
    $_POST['hunden']) || 
       empty(
    $_POST['ras']) || 
       empty(
    $_POST['alder']) || 
       empty(
    $_POST['regnr']) || 
       empty(
    $_POST['mednr']) || 
       empty(
    $_POST['skott'])) 
    {
        
    $errors .= "\n Fel: Fält med * måste vara korrekt ifyllda";
    }

    $time time() + 7200;
    $skicka date('Y-m-d H:i'$time);;
    $datum $_POST['datum'];
    $name $_POST['name']; 
    $tele $_POST['tele']; 
    $email_address $_POST['email']; 
    $hunden $_POST['hunden']; 
    $ras $_POST['ras']; 
    $alder $_POST['alder']; 
    $regnr $_POST['regnr']; 
    $mednr $_POST['mednr']; 
    $skott $_POST['skott']; 
    $message $_POST['message']; 

    if (!
    preg_match(
    "~^SE?\d{5}/\d{4}$~",
    $regnr))
    {
        
    $errors .= "\n Fel: Ogiltig Regnr/Tävlingslicensnr";
    }

    if (!
    preg_match(
    "/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i"
    $email_address))
    {
        
    $errors .= "\n Fel: Ogiltig E-mail adress";
    }

    if( empty(
    $errors))
    {
        
    $to $myemail ', ' $email_address
        
    $email_subject "Ny anmälan";
        
    $email_body "Du har en ny anmälan.".
        
    "\n Anmälan skickades in $skicka och här är de fullständiga uppgifterna:\n\n Datum för BPH: $datum \n Name: $name \n Telefonnummer: $tele \n E-mail adress: $email \n Hundens namn: $hunden \n Hundens ras: $ras \n Hundens födelsedag: $alder \n Hundens Regnr: $regnr \n Medlemsnummer i klubb: $mednr \n Önskas skottprov?: $skott \n Övrigt: \n $message"
        
        
    $headers "From: noreply@minmail\n";
        
    $headers .= "Reply-To: $email_address";
        
        
    mail($to,$email_subject,$email_body,$headers);
        
    //redirect to the 'thank you' page
        
    header('Location: tack-for-anmalan.html');

    ?>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
    <html>
    <head>
        <title>BPH anmälan</title>
    </head>

    <body>
    <!-- This page is displayed only if there is some error -->
    <?php
    echo nl2br($errors);
    ?>


    </body>
    </html>

  • #2
    Regular Coder
    Join Date
    Sep 2011
    Posts
    410
    Thanks
    18
    Thanked 26 Times in 26 Posts
    I'm not sure if you need to change anything php/form related, to handle the correct characters in the string, however I'm sure if it's a problem with the email not showing correctly you'll need to specify the character set as UTF-8.

    Add this:
    PHP Code:
    $headers .= "Content-Type: text/html; charset=UTF-8"
    The content type should be text/plain If you're using plain text, but keep it that way if you want to use HTML code instead.
    If I've helped you out, show your appreciation by clicking the "Thanks" link as well as a link below!

    AdFly
    Facebook | Twitter
    Google | YouTube

  • #3
    New Coder
    Join Date
    Dec 2011
    Posts
    35
    Thanks
    6
    Thanked 0 Times in 0 Posts
    Sorry to say, but non of them works.
    I've tried several suggestion but there's still some issue with åäö

  • #4
    Regular Coder
    Join Date
    Sep 2011
    Posts
    410
    Thanks
    18
    Thanked 26 Times in 26 Posts
    Echo out the variables and make sure they're correct, you may need to change something with the php/html, I'm not too sure.
    If I've helped you out, show your appreciation by clicking the "Thanks" link as well as a link below!

    AdFly
    Facebook | Twitter
    Google | YouTube

  • #5
    New Coder
    Join Date
    Dec 2011
    Posts
    35
    Thanks
    6
    Thanked 0 Times in 0 Posts
    Again. I'm kinda new to this
    What do you mean with echoing it out?

  • #6
    New to the CF scene
    Join Date
    May 2014
    Location
    Liverpool, UK
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Injen View Post
    Again. I'm kinda new to this
    What do you mean with echoing it out?
    So your variables are:

    $time, $skicka, $datum, $name, $tele, $email_address, $hunden, $ras, $alder, $regnr, $mednr, $skott, $message

    And by echo is a php function

    PHP Code:
    <? 

    echo $tele;
    echo 
    $ras;
    echo 
    $alder;
    echo 
    $message;

    ?>
    OR
    PHP Code:
    <? 

    echo $email_body;

    ?>
    ..and so on , putting this within your code would "output" these variables to the browser allowing you to view them when you view the page.. The second example would display the entire email contents.. "Echoing" these variables will just help you to figure out where the issue is starting.

    I don't know if this would help you but you could also try utf8_encode

    Replace your current $email_body with the following:

    PHP Code:

    $email_body 
    =  utf8_encode("Du har en ny anmälan."
        
    "\n Anmälan skickades in $skicka och här är de fullständiga uppgifterna:\n\n Datum för BPH: $datum \n Name: $name \n Telefonnummer: $tele \n E-mail adress: $email \n Hundens namn: $hunden \n Hundens ras: $ras \n Hundens födelsedag: $alder \n Hundens Regnr: $regnr \n Medlemsnummer i klubb: $mednr \n Önskas skottprov?: $skott \n Övrigt: \n $message"); 
    Run your script and then check your email to see if this has changed it at all.

  • #7
    New Coder
    Join Date
    Dec 2011
    Posts
    35
    Thanks
    6
    Thanked 0 Times in 0 Posts
    Hi again and thanks for the answer.
    $email_body = utf8_encode did not work. Same as before.

    When echoing it out the text looks as the mail, åäö are wrong in other words :/

  • #8
    New Coder
    Join Date
    Dec 2011
    Posts
    35
    Thanks
    6
    Thanked 0 Times in 0 Posts
    Bump


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •