473,657 Members | 2,497 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 17596
On Mar 27, 11:55 am, "Ciuin" <c...@gmx.dewro te:
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.dewro te:
>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.dewr ote:
>
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_printab le_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
4418
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 characters as possible will be matched. the regular expression module fails to perform non-greedy matches as described in the documentation: more than "as few characters as possible"
5
3742
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 their dtor is called immediately and not at the end of the function. to be able to use return objects (to avoid copying) i often assign them to a const reference. now, casting a const return object from a function to a non-const reference to this...
3
12226
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 nonblocking mode in c++? I did something ugly like --- c/c++ mixture --- mkfifo( "testpipe", 777);
25
7608
by: Yves Glodt | last post by:
Hello, if I do this: for row in sqlsth: ________pkcolumns.append(row.strip()) ________etc without a prior:
32
4507
by: Adrian Herscu | last post by:
Hi all, In which circumstances it is appropriate to declare methods as non-virtual? Thanx, Adrian.
8
3501
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 cannot load/unload/reload extensions into my large and slow-to-load application during development without restarting the process then the disadvantages may outweigh the advantages. I've got a mixed-mode program in which I create a new AppDomain...
14
8420
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
6108
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 pointers, but I'm not sure. Please help. The code: void equate(matrix *A, matrix *B) { int i, j; assert(A.row_dim == B.col_dim && A.col_dim == B.col_dim); for(i=0; i < A.row_dim; i++) for(j=0; j < A.col_dim; j++)
0
2335
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 jobs. When a non-secure page references a secure page with relative URL, the web server generates error until absolute URL with https prefix is used. On the other hand when a secure page references a non-secure page, the non-secure page will be...
12
29853
by: puzzlecracker | last post by:
is it even possible or/and there is a better alternative to accept input in a nonblocking manner?
0
8305
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
8823
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
8603
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7320
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...
1
6163
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4151
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4301
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2726
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1944
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.