x10Hosting Forums

Corporate Free Hosting for the Masses.



Register

Reply
 
LinkBack Thread Tools Display Modes
x10Hosting Member

Join Date: Jun 2008
Posts: 25
Credits: 297
heinzketchup is on a distinguished road
Location: AUSTRIA xD

Quote  
08-09-2008, 12:12 PM
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 12:12 PM. Reason: Automerged Doublepost
Reply With Quote
heinzketchup is offlineReport Post
x10 Lieutenant

Join Date: Oct 2007
Posts: 438
Credits: 4,202
mattura is just really nice
Quote  
08-13-2008, 07:36 AM
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 
__________________
----
Please donate credits if you had a really good reply from me! Rep is also appreciated. Thanks
matt.elementfx.com
Reply With Quote
mattura is offlineReport Post
x10Hosting Member

Join Date: Jun 2008
Posts: 25
Credits: 297
heinzketchup is on a distinguished road
Location: AUSTRIA xD

Quote  
08-13-2008, 12:44 PM
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
Reply With Quote
heinzketchup is offlineReport Post
x10Hosting Member

Join Date: Jun 2008
Posts: 25
Credits: 297
heinzketchup is on a distinguished road
Location: AUSTRIA xD

Quote  
08-21-2008, 02:39 PM
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 With Quote
heinzketchup is offlineReport Post
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Another mail problem garrettroyce Free Hosting 0 07-18-2008 03:51 PM
PHP MAIL function returned FALSE for the last 2 hours bakakunbakachan Free Hosting 0 05-26-2008 03:23 PM
problem in php mail function and smtp idrees Free Hosting 2 02-08-2008 06:16 PM
can't send email by using mail() in my php program. henry Free Hosting 1 10-21-2007 01:42 AM


All times are GMT -5. The time now is 02:52 PM. Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.2.0 RC7
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios

Credit Counseling | Ringtones | Per Insurance | Mortgages | Dune