Connecting Tech Pros Worldwide Forums | Help | Site Map

correctly getting utf8 characters in the content of an e-mail

lionel
Guest
 
Posts: n/a
#1: Aug 9 '07
Hi,

The HTML of my website is produced in UTF-8.
I've got a contact form with a simple textearea.

When I send this text :
----------------
This is some text
with a second line
----------------

My PHP script sends it ($message) by e-mail :

mail('me@localhost', 'message from contact', utf8_decode($message)) ;

This is what I get in the e-mail :

This is some textwith a second line

I can't get the "\n" character.

I also tried this way :

$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
mail('me@localhost', 'message from contact', utf8_decode(nl2br($message)),
$headers) ;

I still get the same thing :

This is some textwith a second line

How can I get the "\n" of the message correctly ?

Thank you in advance,

:: Lionel ::



burgermeister01@gmail.com
Guest
 
Posts: n/a
#2: Aug 9 '07

re: correctly getting utf8 characters in the content of an e-mail


On Aug 9, 3:12 am, "lionel" <lio...@nospam.orgwrote:
Quote:
Hi,
>
The HTML of my website is produced in UTF-8.
I've got a contact form with a simple textearea.
>
When I send this text :
----------------
This is some text
with a second line
----------------
>
My PHP script sends it ($message) by e-mail :
>
mail('me@localhost', 'message from contact', utf8_decode($message)) ;
>
This is what I get in the e-mail :
>
This is some textwith a second line
>
I can't get the "\n" character.
>
I also tried this way :
>
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
mail('me@localhost', 'message from contact', utf8_decode(nl2br($message)),
$headers) ;
>
I still get the same thing :
>
This is some textwith a second line
>
How can I get the "\n" of the message correctly ?
>
Thank you in advance,
>
:: Lionel ::

If you need to handle UTF-8 I found the following library to be
helpful. As far as I can remember, this will actually translate it
into a corresponding ASCII string, so I don't think any mail servers
that also have issues with UTF-8 should have any issues either. Hope
it helps!

http://www.phpwact.org/php/i18n/utf-8


lionel
Guest
 
Posts: n/a
#3: Aug 11 '07

re: correctly getting utf8 characters in the content of an e-mail


If you need to handle UTF-8 I found the following library to be
Quote:
helpful. As far as I can remember, this will actually translate it
into a corresponding ASCII string, so I don't think any mail servers
that also have issues with UTF-8 should have any issues either. Hope
it helps!
>
http://www.phpwact.org/php/i18n/utf-8
>
Thanks !

I've found what the pb was : I sent the textarea content via an ajax get
query. after tracing each character and its ascii code, it appears that the
"\r\n" characters are present before the ajax get query (traced without pb
in javascript) and disappears in the php code. I used the following trick. I
replaced "\r\n" by "__r__n" in javascript and I replace "__r__n" by "\r\n"
in php. I assume it's not really a solution but I couldn't find any better
one. maybe sending in an ajax post query could solve the pb, I didn't try.

:: Lionel ::


Closed Thread