+ Reply to Thread
Results 1 to 4 of 4

Thread: Utf-8 encoded PHP-mail (!subject umlauts problem!)

  1. #1
    heinzketchup is offline x10Hosting Member heinzketchup is an unknown quantity at this point
    Join Date
    Jun 2008
    Location
    AUSTRIA xD
    Posts
    25

    Utf-8 encoded PHP-mail (!subject umlauts problem!)

    the problem:
    you want to send a php mail with utf-8 encoded content and subject(so that the umlaut letters: ö ä ü ß etc. are not shown like this: ö ä ü)... this ain't as easy as you think! it took me about 1 1/2 days to find this solution from this resource: http://sagmueller.net/php-tut/mails.html

    I roll it up from the beginning...

    i start with the content:
    you only have to put this in your php document into the <head> tag:
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

    that's it, now your content is internationally shown the right way... you don't have to worry about this anymore...

    now to the problem with the subject that is (for some stupid ASCII reason) still shown wrong...
    if your subject is this: $subject="ö ä ü ß";
    you only need to write in the next line: $subject = "=?utf-8?b?".base64_encode($subject)."?=";

    thats it! we can now start writing the mailing function:
    I guess the best way to explain this is just to paste the complete document...

    ---
    <!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>your header here</title>
    </head>
    <body>
    <?
    $from="123@456.asdf";
    $to = "12345@789.com";//your adress here
    $subject = "ö ä ü ß";//your subject here
    $subject = "=?utf-8?b?".base64_encode($subject)."?=";
    $message = "ä ö ü ß are shown correctly."; //Mail content here (can be html!)
    $headers = "From: $from";
    $headers .= "\r\n"; //(This is to write paragraphs windows conform...)
    $headers .= "Content-type: text/plain";
    $headers .= "\r\n\r\n";
    mail($to, $subject, $message, $headers);
    echo 'mail sent!';
    ?>
    </body>
    </html>
    ---
    Thanks for reading my Tut(was my first one, guess everyone noticed that)
    PS: you can also send attachments with php!

    Rock On Guys->bring me credits (what ever they are used for!?!?)
    Edit:
    oh man... this will noone ever read! why i do this?
    Last edited by heinzketchup; 08-09-2008 at 11:12 AM. Reason: Automerged Doublepost

  2. #2
    mattura's Avatar
    mattura is offline x10 Elder mattura is an unknown quantity at this point
    Join Date
    Oct 2007
    Posts
    563

    Re: Utf-8 encoded PHP-mail (!subject umlauts problem!)

    Nice one.

    You say the mail content can be html - well yes, but you should put "text/html" instead of "text/plain"

    Also, you can specify the character set in the same header:
    PHP Code:
     $headers.="Content-Type: text/html; charset=iso-8859-1\r\n"//default character set

    or

     
    $headers.="Content-Type: text/html; charset=utf-8\r\n"//utf-8 
    ----
    Life is a game. The conception is terrible but the graphics are amazing!
    matt.elementfx.com

  3. #3
    heinzketchup is offline x10Hosting Member heinzketchup is an unknown quantity at this point
    Join Date
    Jun 2008
    Location
    AUSTRIA xD
    Posts
    25

    Re: Utf-8 encoded PHP-mail (!subject umlauts problem!)

    Quote Originally Posted by mattura View Post
    Nice one.
    $headers.="Content-Type: text/html; charset=utf-8\r\n"; //utf-8
    [/php]
    cool, didn't know that \r\n in the header is also possible! I copied a solution where they handled it with an if statement and i use it in a loop, so i guess this is also a real performance advantage, i will change this.

    Thanks
    PS: yeah i got someone reading this

  4. #4
    heinzketchup is offline x10Hosting Member heinzketchup is an unknown quantity at this point
    Join Date
    Jun 2008
    Location
    AUSTRIA xD
    Posts
    25

    Re: Utf-8 encoded PHP-mail (!subject umlauts problem!)

    well... suddenly this works too... but i still have the problem with the longer script...

    header:
    $headers .= 'From: '.$SenderName.' <'.$SenderMail.'>'.$eol;
    $headers .= "Message-ID: <".$Momentn."@".$Servername.">".$eol;
    $headers .= 'Date: '.date("r").$eol;
    $headers .= 'Sender-IP: '.$_SERVER["REMOTE_ADDR"].$eol;
    $headers .= 'X-Mailser: iPublications Adv.PHP Mailer 1.6'.$eol;
    $headers .= 'MIME-Version: 1.0'.$eol;

+ Reply to Thread

Similar Threads

  1. Another mail problem
    By garrettroyce in forum Free Hosting
    Replies: 0
    Last Post: 07-18-2008, 02:51 PM
  2. PHP MAIL function returned FALSE for the last 2 hours
    By bakakunbakachan in forum Free Hosting
    Replies: 0
    Last Post: 05-26-2008, 02:23 PM
  3. problem in php mail function and smtp
    By idrees in forum Free Hosting
    Replies: 2
    Last Post: 02-08-2008, 05:16 PM
  4. Replies: 1
    Last Post: 10-21-2007, 12:42 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers