Connecting Tech Pros Worldwide Forums | Help | Site Map

umlaut in mail sent by php?

Oliver Spiesshofer
Guest
 
Posts: n/a
#1: Jul 17 '05
Hi,

I am trying to send emails with the php Mail function, but umlaut and other
special characters are not displayed correctly. Actually they are replaced
by large X's. I checked if there is an error on the receiving side, but
both thunderbird and squirrelmail do the same!

any Idea what is wrong? do I have to make a mb_string_recode? but to what
charset?

The emails are sent in UTF-8 encoding, and the umlaute in the email body
display just perfectly!

Oliver


Philip Ronan
Guest
 
Posts: n/a
#2: Jul 17 '05

re: umlaut in mail sent by php?


Oliver Spiesshofer wrote:
[color=blue]
> Hi,
>
> I am trying to send emails with the php Mail function, but umlaut and other
> special characters are not displayed correctly. Actually they are replaced
> by large X's. I checked if there is an error on the receiving side, but
> both thunderbird and squirrelmail do the same!
>
> any Idea what is wrong? do I have to make a mb_string_recode? but to what
> charset?
>
> The emails are sent in UTF-8 encoding, and the umlaute in the email body
> display just perfectly!
>
> Oliver[/color]

Are you saying they appear correctly in the email body, but not in the
headers (subject, etc.)?

I think internet headers have to be sent as 7-bit data. To send non-ASCII
characters you have to use an "encoded word" as defined in RFC 2047. For
example, "München" can be encoded like this:

=?iso-8859-1?q?M=FCnchen?=

Obviously that uses iso-8859-1 encoding, but you get the picture.

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
PHILIP A. RONAN
Freelance Japanese Translator
205 Hamlin Lane, Exeter EX1 2SQ, England
Tel/Fax: +44 (0) 1392 435019
Email: mail@japanesetranslator.co.uk
http://www.japanesetranslator.co.uk
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

NC
Guest
 
Posts: n/a
#3: Jul 17 '05

re: umlaut in mail sent by php?


Oliver Spiesshofer wrote:[color=blue]
>
> I am trying to send emails with the php Mail function, but
> umlaut and other special characters are not displayed correctly.
> Actually they are replaced by large X's. I checked if there
> is an error on the receiving side, but both thunderbird and
> squirrelmail do the same!
>
> any Idea what is wrong?[/color]

Try this:

$subject = mb_convert_encoding($subject, 'ISO-8859-1', 'UTF-8');

And make sure you have this header:

Content-Transfer-Encoding: 8 bit

Cheers,
NC

Oliver Spiesshofer
Guest
 
Posts: n/a
#4: Jul 17 '05

re: umlaut in mail sent by php?


"NC" <nc@iname.com> wrote in news:1109354489.489314.276270
@g14g2000cwa.googlegroups.com:
[color=blue]
> $subject = mb_convert_encoding($subject, 'ISO-8859-1', 'UTF-8');[/color]

thats what I did now.
Hoever, it still does not arrive in the end properly.
Here is the part of my headers:

Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: 8bit
Subject: Berliner Techno-Club Tresor schlieXt nach 15 Jahren

The script which is doing it now produces a logfile, and the title in the
logfile is correct! If I use ASCII instead of ISO as an encoding, I get a ?
instead of a X for invalid letters....

any other ideas what I could do?

Oliver


Philip Ronan
Guest
 
Posts: n/a
#5: Jul 17 '05

re: umlaut in mail sent by php?


Oliver Spiesshofer wrote:
[color=blue][color=green]
>> $subject = mb_convert_encoding($subject, 'ISO-8859-1', 'UTF-8');[/color]
>
> thats what I did now.
> Hoever, it still does not arrive in the end properly.
> Here is the part of my headers:
>
> Content-Type: text/html; charset=utf-8
> Content-Transfer-Encoding: 8bit
> Subject: Berliner Techno-Club Tresor schlieXt nach 15 Jahren[/color]

That's because you're putting 8-bit data in a mail header. Mail headers can
only contain 7-bit data. I mentioned that already.
[color=blue]
> The script which is doing it now produces a logfile, and the title in the
> logfile is correct! If I use ASCII instead of ISO as an encoding, I get a ?
> instead of a X for invalid letters....[/color]

That's because there is no umlaut in the ASCII character set
[color=blue]
> any other ideas what I could do?[/color]

1. Read RFC 2047
2. Read my last post in this thread

--
phil [dot] ronan @ virgin [dot] net
http://vzone.virgin.net/phil.ronan/


Manuel Lemos
Guest
 
Posts: n/a
#6: Jul 17 '05

re: umlaut in mail sent by php?


Hello,

on 02/25/2005 08:51 AM Oliver Spiesshofer said the following:[color=blue]
> I am trying to send emails with the php Mail function, but umlaut and other
> special characters are not displayed correctly. Actually they are replaced
> by large X's. I checked if there is an error on the receiving side, but
> both thunderbird and squirrelmail do the same!
>
> any Idea what is wrong? do I have to make a mb_string_recode? but to what
> charset?
>
> The emails are sent in UTF-8 encoding, and the umlaute in the email body
> display just perfectly![/color]

You do not need to encode in UTF. You just need to encode with
quoted-printable for characters in the body and q-encoding for
characters in the headers.

Take a look at this class can can encode and send messages properly and
even comes with an example of how to send messages with accents:

http://www.phpclasses.org/mimemessage


--

Regards,
Manuel Lemos

PHP Classes - Free ready to use OOP components written in PHP
http://www.phpclasses.org/

PHP Reviews - Reviews of PHP books and other products
http://www.phpclasses.org/reviews/

Metastorage - Data object relational mapping layer generator
http://www.meta-language.net/metastorage.html
Oliver Spiesshofer
Guest
 
Posts: n/a
#7: Jul 17 '05

re: umlaut in mail sent by php?


Philip Ronan <invalid@invalid.invalid> wrote in
news:BE467201.2C022%invalid@invalid.invalid:
[color=blue]
> 1. Read RFC 2047
> 2. Read my last post in this thread[/color]

thanks. I got now what you meant.

I found the (IMHO) easiest way to deal with it.
I simply run the subject through a mb_encode_mimeheader().

This worked very nicely.

Oliver


Closed Thread