PHP Classes

Special characters when processing email sent from gmail account

Recommend this page to a friend!

      PHP MIME Email Message Parser  >  All threads  >  Special characters when processing...  >  (Un) Subscribe thread alerts  
Subject:Special characters when processing...
Summary:Special characters when processing email sent from gmail account
Messages:6
Author:Raja Sekhar
Date:2011-12-05 20:22:42
Update:2012-08-30 06:38:10
 

  1. Special characters when processing...   Reply   Report abuse  
Picture of Raja Sekhar Raja Sekhar - 2011-12-05 20:22:42
Hi

We are using the MIME Parser to do some inbound email processing for a mailing list and then form the the e-mail again and send that to few member email ids.

One issue we are facing is the introduction of special characters (such as ����) in the email when we parse the email that was sent from gmail account from the browser. The characters appear randomly in place of whitespaces or newlines. I am pasting the code below we are using (stripped the logging/error handling etc.)

$mime=new mime_parser_class;
$mime->decode_bodies = 1;
$mime->ignore_syntax_errors = 1;
$mime->track_lines = 1;
$mime->decode_headers = 1;
$mime->decode_bodies = 1;
$parameters=array('Data'=>$raw_email, 'SkipBody'=>0);

$mime->Decode($parameters, $decoded);
$mime->Analyze($decoded[$message], $results));

This does not happen for any other emails - only for emails sent from gmail over the web. We are not able to figure out the reason for this, though it looks like some character encoding issue. Any pointers would be appreciated.

  2. Re: Special characters when processing...   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2011-12-06 00:30:07 - In reply to message 1 from Raja Sekhar
If you see those characters in the parsed message, it is because they are used in the original message that is sent. The class does not alter the message contents.

If you are not sure, you may want to upload the original message complete with headers so I can confirm that it is in the original message.

  3. Re: Special characters when processing...   Reply   Report abuse  
Picture of Raja Sekhar Raja Sekhar - 2012-03-01 09:51:51 - In reply to message 2 from Manuel Lemos
Hi

I finally resolved this problem. As suspected, this was related to chacter encoding of the incoming mail. I am now converting all the mail I parse to UTF8 and it works like a charm.

thank you,
Rajs

  4. Re: Special characters when processing...   Reply   Report abuse  
Picture of Michael Delle Michael Delle - 2012-08-25 21:20:35 - In reply to message 3 from Raja Sekhar
Raja,

Are you using iconv() to convert the email to UTF-8?

  5. Re: Special characters when processing...   Reply   Report abuse  
Picture of Raja Sekhar Raja Sekhar - 2012-08-30 06:22:23 - In reply to message 4 from Michael Delle
Yes, I am using iconv to convert to utf-8

  6. Re: Special characters when processing...   Reply   Report abuse  
Picture of Michael Delle Michael Delle - 2012-08-30 06:37:39 - In reply to message 5 from Raja Sekhar
Thanks for getting back to me, I was just curious since there is a few way of doing it.

I ended up making this little function: http://pastebin.com/MKtFzMnb