umlaut in mail sent by php?

This is a discussion on umlaut in mail sent by php? within the PHP Language forums, part of the PHP Programming Forums category; Hi, I am trying to send emails with the php Mail function, but umlaut and other special characters are not ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-25-2005
Oliver Spiesshofer
 
Posts: n/a
Default umlaut in mail sent by php?

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

Reply With Quote
  #2 (permalink)  
Old 02-25-2005
Philip Ronan
 
Posts: n/a
Default Re: umlaut in mail sent by php?

Oliver Spiesshofer wrote:

> 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


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
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

Reply With Quote
  #3 (permalink)  
Old 02-25-2005
NC
 
Posts: n/a
Default Re: umlaut in mail sent by php?

Oliver Spiesshofer wrote:
>
> 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?


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

Reply With Quote
  #4 (permalink)  
Old 02-26-2005
Oliver Spiesshofer
 
Posts: n/a
Default Re: umlaut in mail sent by php?

"NC" <nc@iname.com> wrote in news:1109354489.489314.276270
@g14g2000cwa.googlegroups.com:

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


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


Reply With Quote
  #5 (permalink)  
Old 02-26-2005
Manuel Lemos
 
Posts: n/a
Default Re: umlaut in mail sent by php?

Hello,

on 02/25/2005 08:51 AM Oliver Spiesshofer said the following:
> 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!


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
Reply With Quote
  #6 (permalink)  
Old 02-26-2005
Philip Ronan
 
Posts: n/a
Default Re: umlaut in mail sent by php?

Oliver Spiesshofer wrote:

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

>
> 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


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.

> 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....


That's because there is no umlaut in the ASCII character set

> any other ideas what I could do?


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

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


Reply With Quote
  #7 (permalink)  
Old 02-27-2005
Oliver Spiesshofer
 
Posts: n/a
Default Re: umlaut in mail sent by php?

Philip Ronan <invalid@invalid.invalid> wrote in
news:BE467201.2C022%invalid@invalid.invalid:

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


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


Reply With Quote
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

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



All times are GMT +1. The time now is 12:15 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0