Mailto with subject

XML, Perl, Python, and other languages can be discussed here, even if it isn't PHP (We might forgive you).

Moderator: General Moderators

Post Reply
User avatar
Sindarin
Forum Regular
Posts: 521
Joined: Tue Sep 25, 2007 8:36 am
Location: Greece

Mailto with subject

Post by Sindarin »

I am trying to add a subject to an e-mail link so I've used the command mailto:a@a.com?subject=test but the problem is the language if I try this with a Greek subject, I get unknown characters in the subject field. I've tried changing my page's encoding to Greek ISO and utf-8, but no good.
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: Mailto with subject

Post by VladSun »

if you wonder how to encode an subject in UTF-8 do it like this:

<?php
mail("timo.witte@kwick.de", "=?UTF-8?B?".base64_encode("also öhm äähh ühh puh ja die Sonderzeichen")."?=", "asbdasdasd bla blabla", $headers);
?>

=UTF-8?B?[Base64 encoded Subject]?=

The B stands for Base64 you could use Q instead of B and encode your UTF-8 string in 7 bit ASCII but base64 is simpler i think.

why encoding?
because you are not allowed to use 8-bit ASCII in mailheaders only 7-bit ASCII is allowed and pure utf-8 uses 8-bit ASCII characters.
There are 10 types of people in this world, those who understand binary and those who don't
User avatar
Sindarin
Forum Regular
Posts: 521
Joined: Tue Sep 25, 2007 8:36 am
Location: Greece

Re: Mailto with subject

Post by Sindarin »

Thanks, I understand now..
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: Mailto with subject

Post by Chris Corbyn »

You can even take it a step further and specify that it's greek.

=?UTF-8*GR?B?[Base64 encoded Subject]?=

That's assuming GR is the language code for greece.

EDIT | To clarify why you'd do that, it's for accessibility. Most screen readers can't read things like greek very well unless you tell them they should be reading greek ;)
Post Reply