473,419 Members | 1,662 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,419 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 17583
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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,...
0
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...
0
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,...
1
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...
0
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,...
0
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...

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.