Page 1 of 2 12 LastLast
Results 1 to 10 of 14

Thread: Problem with specials characters and php

  1. #1
    Join Date
    Apr 2007
    Posts
    59
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default Problem with specials characters and php

    When my form is filled out with special characters I get a mail with strange characters eventhough I have set the charset to UTF-8. I made a test form as example, if you like to have a try.

    Can someone tell me how I can force the form to display the characters correctly?

    The problem is in the php script, line 14: (élève / élève) should display the word élève on the mail that I get.

    HTML Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>test specials characters</title>
    </head>
    
    <body>
    
    After filling out this form, a mail will be sent .
    
    <form name="test" action="test1.php"   method="POST">
    
    <div>
    
        <table border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td>Enter  
      &eacute;l&egrave;ve<br />
            <input type="text" name="name" size="40" /><br /></td>
          </tr>
          <tr>
            <td>email<br />
            <input type="text" name="email" size="40" /></td>
          </tr>
          
          <tr>
            <td><input name="submit" type="submit" value=" send " />
              </td>
          </tr>
        </table>
    
    </div>
    </form>
    </body>
    </html>
    And the reply script:

    PHP Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>Untitled Document</title>
    </head>
    <body>
    <?php 
    $email 
    $_POST['email'];
    $name $_POST['name'];
    // Print the message.
    print " Thank you, you enter    &eacute;l&egrave;ve";
    // Send the email.
    $body " You have enter $name (&eacute;l&egrave;ve / élève), thank you "
    mail ("$email,mymail@gmail.com"'test specials characters'$body);
    ?>
    </body>
    </html>
    Last edited by paldo; 02-17-2014 at 09:05 AM.

  2. #2
    Join Date
    Feb 2014
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by paldo View Post

    <?php
    $email = $_POST['email'];
    $name = $_POST['name'];
    // Print the message.
    print " Thank you, you enter &eacute;l&egrave;ve";
    // Send the email.
    $body = " You have enter $name (&eacute;l&egrave;ve / élève), thank you ";
    mail ("$email,mymail@gmail.com", 'test specials characters', $body);
    ?>
    The problem is, you are sending a pure text mail, so the & doesn't have the same meaning as in HTML. You can find a short description on sending an HTML-Mail here: css-tricks.com/sending-nice-html-email-with-php/

    Good Luck!
    Last edited by djr33; 02-13-2014 at 05:48 PM. Reason: hotlink removed

  3. #3
    Join Date
    Apr 2007
    Posts
    59
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default

    Thank you Ozinder, very useful link for a better presentation of my text mail . Unfortunately it doesn't solve my problem of special characters. My text mail is in french and in the text I have to use many special characters.

  4. #4
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    IF you are using utf-8, as you say, then there is no need for encoding those characters. utf-8 supports all these chartacters natively. How are you setting the character encoding?

  5. #5
    Join Date
    Apr 2007
    Posts
    59
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default

    I have learned that if I'm using special characters I have to set the charset to utf-8. Doing so, my php form print the characters correctly on the browser, parse the value with special characters also correctly on the mail that I receive but the text containing special characters that I have add to the mail are not displayed correctly. I think that my php form is confused when the $name contain a special character. In fact if the entered word $name doesn't contain a special character, my mail is displayed correctly.

  6. #6
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    You need to be sure that the php script, the output html (the "webpage" itself) and the email are all encoded with, and declared as, utf-8.

    In general, browsers encode form submissions with whatever encoding the webpage was sent in, so that's your first step. Note that many web hosts automatically send a charset declaration for you, and it's not always utf-8 (some version of ISO-8859 is very common).

    Setting the charset in your HTML markup is not sufficient in most cases ([almost?] all browsers will ignore the html charset if the server sends a content-type header). If the browser is unsure about what character encoding to use, many (especially IE) will try to auto-detect it by reading the first few hundred bytes or so: because this is probably all in the <head> section of your page, it will all probably be standard latin characters (which are the same in ASCII and UTF-8, and therefore indistinguishable).

    The same points apply to the email itself: make sure your php script is encoded with utf-8, and make sure to specify the charset as utf-8.

  7. #7
    Join Date
    Feb 2014
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by paldo View Post
    My text mail is in french and in the text I have to use many special characters.
    Perhaps I missunderstand: Do you send a text mail or a HTML-Mail?

    If you use HTML, you will perhaps need to replace the special chars entered in the form with their ampersand representation in HTML.
    If you use UTF-8 in your form, your strings and your mail, you will need
    Code:
    Content-Type:text/plain;charset=utf-8
    in your mail-header.

    Perhaps this one helps you a step along.

  8. #8
    Join Date
    Apr 2007
    Posts
    59
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default

    I'm stuck, no improvement. I have change the form a little bit so that you can test if you wish.
    http://www.anti-aging-solutions.ch/j...est/test1.html


    HTML Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>test specials characters</title>
    </head>
    
    <body>
    
    After filling out this form, a mail will be sent to you . Try first by filling out with a word not containing a special character, and then another mail containing a special character. You will see that in the first mail my plain text that contain special character will display correctly, but not in the second mail. <br/><br/> 
    
    <form name="test" action="test1.php"   method="POST">
    
    <div>
    
        <table border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td>Enter for example eleve in the first mail and   
      &eacute;l&egrave;ve in the second<br />
            <input type="text" name="name" size="40" /><br /></td>
          </tr>
          <tr>
            <td>email<br />
            <input type="text" name="email" size="40" /></td>
          </tr>
          
          <tr>
            <td><input name="submit" type="submit" value=" send " />
              </td>
          </tr>
        </table>
    
    </div>
    </form>
    </body>
    </html>
    And the php script:

    PHP Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>Untitled Document</title>
    </head>
    <body>
    <?php 
    $email 
    $_POST['email'];
    $name $_POST['name'];


    // Print the message.
    print " Thank you, you enter    &eacute;l&egrave;ve";


    // Send the email.
    $headers .= "MIME-Version: 1.0\r\n";
    $headers .= "Content-Type: text/plain; charset=UTF-8\r\n";
    $message .= " You have enter $name (élève), thank you ";
                
     
    mail ("$email"'test specials characters'$message$headers);
    ?>
    </body>
    </html>

    Thanks for your help.

  9. #9
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    First, your test page is not declared as UTF-8.
    Quote Originally Posted by http://www.anti-aging-solutions.ch/jeunesse/test/test1.html
    Content-Type: text/html; charset=ISO-8859-1
    See my post above. You need to send an HTTP header with the correct charset: the charset in your html markup will not be sufficient.

    Your code that send the email looks correct, except that the first header line should be assigned, not appended:
    PHP Code:
    #  NO
    # $headers .= "MIME-Version: 1.0\r\n";

    # Yes
    $headers "MIME-Version: 1.0\r\n"

  10. #10
    Join Date
    Apr 2007
    Posts
    59
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default

    You mean the form page (../test1.html) is not declared UTF-8? Is <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> not the correct declaration? What else and where do I have to declare? Thanks

Similar Threads

  1. problem with chinese characters
    By paldo in forum HTML
    Replies: 8
    Last Post: 02-11-2014, 08:39 PM
  2. problem with characters...
    By jonybigude in forum Dynamic Drive scripts help
    Replies: 4
    Last Post: 05-14-2011, 10:54 PM
  3. Fix to problem displaying RSS feed with accented characters
    By robokev in forum Dynamic Drive scripts help
    Replies: 1
    Last Post: 09-22-2008, 05:03 AM
  4. Ajax Tabs Content Script - problem with non alpha-numeric characters
    By masamasa in forum Dynamic Drive scripts help
    Replies: 1
    Last Post: 07-25-2008, 02:54 PM
  5. Parsing problem with characters " & < > "
    By SuperLes2006 in forum JavaScript
    Replies: 5
    Last Post: 01-17-2006, 04:21 PM

Bookmarks

Posting Permissions

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