imekul Posted October 12, 2010 Share Posted October 12, 2010 I have piping set up, where when I send an e-mail to a certain address, a script executes. This script will parse the e-mail and will post the body of the e-mails (along with a picture, if attached) to a blog. This all works okay, except the problem I keep running into is when I send from different devices (desktop, Android phone, BlackBerry), the e-mails have different character sets or encoding. So one e-mail will show up just fine, and then the body of another will look something like this: --90e6ba6e83a0846c8504926b9478 Content-Type: text/html; charset=ISO-8859-1 This is the content of the e-mail. --90e6ba6e83a0846c8504926b9478-- So what I'm wondering is if there is any way to detect the charset/encoding and automatically decode it properly? The only solution I have so far -- and I'm not very good with PHP, I'll admit -- is to just "hack" my way through, by using stristr() to see if the body contains certain characters (like "ISO-8859-1"), and then extracting the text that is in between, say, "ISO-8859-1" and "--". Of course, this is very crude, and has many problems on its own. So what I am looking for is if there is some sort of way to automatically get the body of an e-mail in plain text, regardless of whether the e-mail has an attachment, how it's encoded, or what mail client was used. Thanks for your time! Quote Link to comment Share on other sites More sharing options...
AbraCadaver Posted October 12, 2010 Share Posted October 12, 2010 This has already been done. Look at phpclasses.org or PEAR for an email parsing or mime class. There are bound to be many other good ones. http://www.phpclasses.org/search.html?words=parse+email&x=0&y=0&go_search=1 http://pear.php.net/package/Mail_mimeDecode Quote Link to comment Share on other sites More sharing options...
chintansshah Posted October 12, 2010 Share Posted October 12, 2010 Please write some code here. Quote Link to comment Share on other sites More sharing options...
imekul Posted October 12, 2010 Author Share Posted October 12, 2010 Thanks, Shawn. I'll take a look at that. Quote Link to comment Share on other sites More sharing options...
imekul Posted October 12, 2010 Author Share Posted October 12, 2010 Are you aware of any samples or examples that show how to do something like this? I found a sample script at http://www.nicholassolutions.com/tutorials/php/index.php#MimeDecode, but it doesn't seem to work fully. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.