473,320 Members | 1,952 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Non-ascii email subject and header encoding

Hi all,

I need to mail() emails with user input that does contain non-ascii
(umlauts, accents) and non-latin (cyrillic) characters in the
"Subject:" and "From:" headers. I understand that they are typically
encoded in UTF8 like this:

=?UTF-8?B?w5Z0emkg0J/RgNC40LLQtdGC?=

but I cannot find a PHP function to encode the input string in this
way. utf8_encode gives me garbled char soup, so what do you use?

Thanks.

Mar 27 '07 #1
4 17579
On Mar 27, 11:55 am, "Ciuin" <c...@gmx.dewrote:
Hi all,

I need to mail() emails with user input that does contain non-ascii
(umlauts, accents) and non-latin (cyrillic) characters in the
"Subject:" and "From:" headers. I understand that they are typically
encoded in UTF8 like this:

=?UTF-8?B?w5Z0emkg0J/RgNC40LLQtdGC?=

but I cannot find a PHP function to encode the input string in this
way. utf8_encode gives me garbled char soup, so what do you use?

Thanks.
Ah well, bad thinking on my part.

Instead of utf8_encode I need base64_encode, of course (as the "...?
B?..." in the code tells me). So this:

$from = "From: =?UTF-8?B?" . base64_encode($_POST['name']) . "?= <" . $
$_POST['email'] . ">\n";

produces a correctly encoded header. Same for subject.

Hope it helps someone.

Mar 27 '07 #2
Ciuin wrote:
On Mar 27, 11:55 am, "Ciuin" <c...@gmx.dewrote:
>Hi all,

I need to mail() emails with user input that does contain non-ascii
(umlauts, accents) and non-latin (cyrillic) characters in the
"Subject:" and "From:" headers. I understand that they are typically
encoded in UTF8 like this:

=?UTF-8?B?w5Z0emkg0J/RgNC40LLQtdGC?=

but I cannot find a PHP function to encode the input string in this
way. utf8_encode gives me garbled char soup, so what do you use?

Thanks.

Ah well, bad thinking on my part.
Was it?
Not really.

Encoding/charsets/headers/content-type/UTF/unicode/etc ALWAYS gives me a
headache. :-/
Confusing stuff, especially when you have to consider a whole range of
receiving clients (different browsers, emailclients, etc).

Regards,
Erwin Moller
>
Instead of utf8_encode I need base64_encode, of course (as the "...?
B?..." in the code tells me). So this:

$from = "From: =?UTF-8?B?" . base64_encode($_POST['name']) . "?= <" . $
$_POST['email'] . ">\n";

produces a correctly encoded header. Same for subject.

Hope it helps someone.

Mar 27 '07 #3
"Ciuin" <ci***@gmx.dewrote:
>
Instead of utf8_encode I need base64_encode, of course (as the "...?
B?..." in the code tells me). So this:

$from = "From: =?UTF-8?B?" . base64_encode($_POST['name']) . "?= <" . $
$_POST['email'] . ">\n";

produces a correctly encoded header. Same for subject.
For completeness, allow me to point out that you can also use
quoted-printable encoding here (you'd use =?utf-8?Q? instead of ...?B?).
Quoted-printable encoding has the "advantage" that ASCII characters survive
unchanged, so if there are ASCII words, they can be read even in their
encoded form.

On the other hand, strings with many non-ASCII characters grow more in
quoted-printable than in base64. Plus, there is no
"quoted_printable_encode" in the standard library, although sources are
available.
--
Tim Roberts, ti**@probo.com
Providenza & Boekelheide, Inc.
Mar 28 '07 #4
Hello,

on 03/27/2007 06:55 AM Ciuin said the following:
Hi all,

I need to mail() emails with user input that does contain non-ascii
(umlauts, accents) and non-latin (cyrillic) characters in the
"Subject:" and "From:" headers. I understand that they are typically
encoded in UTF8 like this:

=?UTF-8?B?w5Z0emkg0J/RgNC40LLQtdGC?=

but I cannot find a PHP function to encode the input string in this
way. utf8_encode gives me garbled char soup, so what do you use?
That is binary q-encoding. It is not quoted-printable but it is similar
for message headers. There is a whole RFC on that subject.

Yoy may want to try the MIME message that can be used to compose and
send messages and supports headers with non-ASCII characters encoded as
UTF-8 or any other encoding.

Take a look at the test_multibyte_message.php example script. It
explains how to send messages in Japanese with encoding ISO-2022-JP, but
you can change that for UTF-8 to support characters of all idioms.

http://www.phpclasses.org/mimemessage
--

Regards,
Manuel Lemos

Metastorage - Data object relational mapping layer generator
http://www.metastorage.net/

PHP Classes - Free ready to use OOP components written in PHP
http://www.phpclasses.org/
Mar 29 '07 #5

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

Similar topics

12
by: lothar | last post by:
re: 4.2.1 Regular Expression Syntax http://docs.python.org/lib/re-syntax.html *?, +?, ?? Adding "?" after the qualifier makes it perform the match in non-greedy or minimal fashion; as few...
5
by: klaus triendl | last post by:
hi, recently i discovered a memory leak in our code; after some investigation i could reduce it to the following problem: return objects of functions are handled as temporary objects, hence...
3
by: Mario | last post by:
Hello, I couldn't find a solution to the following problem (tried google and dejanews), maybe I'm using the wrong keywords? Is there a way to open a file (a linux fifo pipe actually) in...
25
by: Yves Glodt | last post by:
Hello, if I do this: for row in sqlsth: ________pkcolumns.append(row.strip()) ________etc without a prior:
32
by: Adrian Herscu | last post by:
Hi all, In which circumstances it is appropriate to declare methods as non-virtual? Thanx, Adrian.
8
by: Bern McCarty | last post by:
Is it at all possible to leverage mixed-mode assemblies from AppDomains other than the default AppDomain? Is there any means at all of doing this? Mixed-mode is incredibly convenient, but if I...
14
by: Patrick Kowalzick | last post by:
Dear all, I have an existing piece of code with a struct with some PODs. struct A { int x; int y; };
2
by: Ian825 | last post by:
I need help writing a function for a program that is based upon the various operations of a matrix and I keep getting a "non-aggregate type" error. My guess is that I need to dereference my...
0
by: amitvps | last post by:
Secure Socket Layer is very important and useful for any web application but it brings some problems too with itself. Handling navigation between secure and non-secure pages is one of the cumbersome...
12
by: puzzlecracker | last post by:
is it even possible or/and there is a better alternative to accept input in a nonblocking manner?
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.