473,654 Members | 3,103 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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@localh ost', 'message from contact', utf8_decode($me ssage)) ;

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@localh ost', 'message from contact', utf8_decode(nl2 br($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 ::
Aug 9 '07 #1
2 2599
On Aug 9, 3:12 am, "lionel" <lio...@nospam. orgwrote:
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@localh ost', 'message from contact', utf8_decode($me ssage)) ;

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@localh ost', 'message from contact', utf8_decode(nl2 br($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
Aug 9 '07 #2
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
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 ::
Aug 11 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
18320
by: Spamtrap | last post by:
I only work in Perl occasionaly, and have been searching for a solution for a conversion, and everything I found seems much too complex. All I need to do is take a simple text file and copy it, however some specific lines are in fact in UTF8 as printed garbagy characters and they need to be converted to Unicode, so that the new text file can be imported into a desktop program and into some Word documents. For the moment I would be...
1
4282
by: Paul | last post by:
Assume you have two varchar (or Text) columns named L and U which are identical except that the charset for L is latin1 and the charset for U is utf8. All the records in L and U are identical in terms of content, consisting of only 7 bit ASCII characters. Both columns have indexes of the same type (e.g. assume Unique indexes if you want). Here's my question: Will the fact that column U has a utf8 charset make select queries run slower on...
7
1676
by: u260044 | last post by:
I have a problem where the French translation for "side" gets converted incorrectly into a datatable from XML. Note: The total XML is at the bottom of the message to keep from distracting from the observation. Note: The characters used in this example are <Text>Côtés</Text> When I put the XML into a datatable doing either of the following it gets
4
11514
by: H Lee | last post by:
Hi, I'm an XML newbie, and not sure if this is the appropriate newsgroup to post my question, so feel free to suggest other newgroups where I should post this message if this is the case. I'm having issues using XmlTextWriter, saving it out to a file with UTF8 encoding, and seeing "dirty", or "human unreadable" characters show up *right before* the XML declaration. I need to have the XML declaration state "encoding = utf-8", but also...
8
20277
by: csanjith | last post by:
Hi, i have a situaion where i need to convert the characters entered in an text field to upper case using C. The configuration id utf8 environment in which user can enter any character (single , double, triple byte etc). I need to convert to upper case only those characters which has got upper case. ie if an user enter bot english and japanese characters in the text field, then I should convert only english characters, not japanese.
18
1608
by: kenny | last post by:
I have a String outputhex which consists of unicodetext translated into hex. example: test = 7400650073007400 now i translate each two characters of the hexstring (outputhex) into byte and then into chars. but this is the point where something is wrong... (having the byteorder mark removed would also be very good) "Schließen" gets to "Schlie鿃攀渀" and so on...
4
2775
by: twigster | last post by:
Hi, I've a pb with utf8 encoding with safari or firefox. I retrieve the response of a XMLHttpRequest and depending if I use safari or firefox I can't manage to get characters like "éàç" to see an illustration you can try the code below : (with this code I get a "é" with firefox but not with safari. I need to add a ut8_decode to get the "é"!)
2
10293
by: Jason | last post by:
Hi, I was wondering if anyone could advise me on this. Right now I am setting up a DB2 UDB V8.2.3 database with UTF8 character set, which will work with a J2EE application running on WebSphere Application Server. I have two questions: 1. How many characters, such as Chinese, Japanese, can a CHAR(128) or
7
13069
by: amygdala | last post by:
Hi, I'm trying to let PHP write a 'sitemap.xml' sitemap for Google and other searchengines. It's working, except that the content in the XML file doesn't seem to be UTF8. (Which it should be, judging by the information given on Google's webmaster helpcenter). The way I test to see if the content is UTF8, is by opening the XML file in notepad and choose 'save as...'. Normally the coding option should be set to UTF8, but now it just...
3
7469
by: Jake | last post by:
I am writing a script that allows people to upload a CSV file for processing and I am having trouble with accented characters. If a UTF-8 encoded file is uploaded, everything works fine. The problem happens when someone uploads a non UTF8 file that happens to have an accented character inside, like é. In this case, the character is converted to a funky symbol, like �. I noticed this explanation in the PHP documentation for the...
0
8372
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8285
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8814
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8706
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8475
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7304
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5621
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4293
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1915
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.