Forum Moderators: coopster
I have an automated mail service on a page in swedish. When the admin fills out a form, the message is sent to a specific number of recievers.
The problem is, that when the admin uses special chars like å ä ö in the subject line, the email subject is transformed to some weird chars in the end.
I use a:
$header.="Content-type: text/html; charset=ISO-8859-1\r\n"; and a html special char converter function that seems to work fine in the main message, but not in the subject.
When I send a message from my main email to myself using a special char in subject, and then look at the source code it looks something like:=?ISO-8859-1?B?5TrkOvY6xTrEOtY=?=
Now, is there some kind of function that converts special chars to theese alien ISO format, or is there anything else i can do to make sure the admin can use any chars he/she likes in the subject?
Any reply would be greatly aprechiated.
The functions you pointed me at did not work as intended, but they gave me something to think about.
It seems that those functions work for icelandic letters, but clearly not swedish.
Two things in their function bothers me:
$text = '=?iso-8859-1?q?';
In my emails when I send special chars it starts with:
=?iso-8859-1?B?
So its a "B" instead of "q". But simply changing the q to a B just caused more strange results.
Second I dont think their code:
$val = ord($string[$i]);
$val = dechex($val);
does what I want with the swedish chars.
I need some kind of conversion table that works for =?iso-8859-1?B?. Does anyone know anything about this?
thanx
Here's the RFC which explains more of the standard
[rfc.net...]
In theory, you could use this:
$subject="whatever";
$mail_subject = "=?iso-8859-1?B?".base64_encode("$subject")."?=";
This works, since the "B" stands for base64 encoding.
But unfortunately, it doesnt work for special chars like åäö.
Im lost here, and nothing out there seems to help.
thanx
Apparently, just defining a string like this:
$subject="åäöÅÄÖ";
and then trying to encode it like:
$encoded="=?ISO-8859-1?B?".base64_encode($subject)."?=";
doesnt work. Why? because .php cant hande special chars in its own document. But if I made a form and the collected the value from the form and converted it like:
$subject = $_POST['subject'];
$encoded="=?ISO-8859-1?B?".base64_encode($subject)."?=";
It suddenly worked! And I even found a better way of converting subjects:
$subject = encode_subject($_POST['subject'],"ISO-8859-1");
function encode_subject($subject,$charset) {
$return = "=?".$charset."?Q?".str_replace("=\r\n", "", preg_replace("/\?/", "=3F", imap_8bit($subject)))."?=";
return $return;
}
Feel free to use it if you ever find it useful.