Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
mikestechs

PHP Contact form input doesnt support diacritics

Recommended Posts

Posted · Original PosterOP

I have small problem with my php contact form code. 
I have my site using diacritics which does work perfectly. But my contact form input after submitting looks like this "ÄÅ¡Å" after using any [0-9] keys for diacritics. 


PHP file: 

    <?php
    
    
    $name = $_POST['name'];
    $email = $_POST['email'];
    $phone = $_POST['phone'];
    $service = $_POST['service'];      
    $message = $_POST['message'];      
    
    $from = $name; 
    $to = 'info@email.com'; 
    $subject = "$name - $service";
     
    $body = "Jméno zákazníka: $name\nE-Mail zákazníka: $email\nTelefonní číslo: $phone\nservice: $service\nZpráva: $message ";
    
    if (mail ($to, $subject, $body, $from, $headers)) {
    $headers = array("Content-Type: text/html; charset=UTF-8");
        } 
        else {
            echo "Failed";
        }
    
    
    ?>

Output after submitting the contact form: 

 

  First Last Name
    
    Jméno zákazníka: Name
    E-Mail zákazníka: email
    Telefonní císlo: phone number
    service: havárii
    Zpráva: Ä�Å¡Å�

the "headers" as name, email, phone, service, message is written with diacritics BUT then the input for example here: Zpráva: ÄÅ¡Å is not supported for some reason.

Also the html file include 

 

   <meta charset="utf-8">

 

Link to post
Share on other sites

Using utf8_encode might work:

utf8_encode($text)

You should also check that the default charset is UTF-8 with phpinfo().


[GUIDE] LGA 771 Mod for Dell Vostro 220 [GUIDE] LGA 775 BSEL Mod [BUILD] The Mighty Radeon-Powered Dell [VIDEO] Evolution of Intel CPUs

Can you game on an 8-year-old i7? Is the 4-year-old GTX 660 still relevant? Upgrading the HP Pro 3500

Main Rig:

Spoiler

CPU Intel Core i7 4930k @ 4.3GHz | Motherboard ASUS P9X79 Deluxe | RAM Hynix 32GB (8x4GB) 2133MHz CL11 | GPU Gigabyte GTX 980Ti G1 Gaming | Case NZXT Phantom 410 | Storage Samsung 850EVO 500GB, Seagate Barracuda 2TB | PSU Cooler Master G650M (650W) | Monitors x1 Dell U2515H, x2 Dell 1907FP | Cooling Noctua NH-D14 w. x2 NF-F12 iPPC-2000 PWM | Keyboard Logitech G610 ORION BROWN | Mouse Logitech Performance MX | OS Microsoft Windows 10 Pro x64

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


×