I’m trying to pipe my incoming mails to a PHP script so I can store them in a database and other things. I’m using the class MIME E-mail message parser (registration required) although I don’t think that’s important.
I have a problem with email subjects. It works fine when the title is in English but if the subject uses non-latin Characters I get something like
=?UTF-8?B?2KLYstmF2KfbjNi0?=
for a title like
یک دو سه
I decode the subject like this:
$subject = str_replace('=?UTF-8?B?' , '' , $subject);
$subject = str_replace('?=' , '' , $subject);
$subject = base64_decode($subject);
It works fine with short subjects with like 10-15 characters but with a longer title I get half of the original title with something like ��� at the end.
If the title is even longer, like 30 characters, I get nothing. Am I doing this right?
Despite the fact that this is almost a year old – I found this and am facing a similar problem.
I’m unsure why you’re getting odd characters, but perhaps you are trying to display them somewhere your charset is unsupported.
Here’s some code I wrote which should handle everything except the charset conversion, which is a large problem that many libraries handle much better. (PHP’s MB library, for instance)
When run through a script and displayed in a browser using UTF-8, the result is:
آزمایش
You would run it like so: