Page 1 of 1

extracting message body from email??

Posted: Fri Jun 10, 2005 8:57 am
by tsg
Hello,

I am trying to extract a message from emails that are forwarded to a script. This would be kind of like a helpdesk type thing.

I can get the subject, from, etc ... but the message body ends up like this:
This is a multi-part message in MIME format.

------=_NextPart_000_0189_01C56D92.92A8DC80
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

The storm was not expected to strengthen into a hurricane. But it could =
drop as much as 5 to 10 inches of rain, and possibly cause flooding in =
western Cuba and tornados in southwestern Florida and the Florida Keys, =
meteorologists said.

"This is going to be a major rainfall event before and ahead of the =
storm," said Trisha Wallace, a hurricane center meteorologist.

Ahead of the storm, steady rainfall and squalls began to hit Florida on =
Thursday.

The Cuban government issued a tropical storm warning for the western =
province of Pinar Del Rio to the capital of Havana. A tropical storm =
warning was also in effect for the Dry Tortugas, a cluster of islands =
about 70 miles west of Key West that comprise a U.S. national park.

Hurricane season began June 1 and ends Nov. 30. Last season, Florida was =
struck by hurricanes Charley, Frances, Ivan and Jeanne; between them, =
the four storms damaged one out of every five homes in the state. The =
storms caused about 130 deaths in the United States and are blamed for =
$22 billion in insured damage.

------=_NextPart_000_0189_01C56D92.92A8DC80
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2900.2627" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DTahoma size=3D2>
<P>The storm was not expected to strengthen into a hurricane. But it =
could drop=20
as much as 5 to 10 inches of rain, and possibly cause flooding in =
western Cuba=20
and tornados in southwestern Florida and the Florida Keys, =
meteorologists=20
said.</P>
<P>"This is going to be a major rainfall event before and ahead of the =
storm,"=20
said Trisha Wallace, a hurricane center meteorologist.</P>
<P>Ahead of the storm, steady rainfall and squalls began to hit Florida =
on=20
Thursday.</P>
<P>The Cuban government issued a tropical storm warning for the western =
province=20
of Pinar Del Rio to the capital of Havana. A tropical storm warning was =
also in=20
effect for the Dry Tortugas, a cluster of islands about 70 miles west of =
Key=20
West that comprise a U.S. national park.</P>
<P>Hurricane season began June 1 and ends Nov. 30. Last season, Florida =
was=20
struck by hurricanes Charley, Frances, Ivan and Jeanne; between them, =
the four=20
storms damaged one out of every five homes in the state. The storms =
caused about=20
130 deaths in the United States and are blamed for $22 billion in =
insured=20
damage.</P></FONT></DIV></BODY></HTML>

------=_NextPart_000_0189_01C56D92.92A8DC80--
Is there a way just to get the message body in a plain text format from the emails forwarded to the script?

Thanks in advance!
Tim

Posted: Fri Jun 10, 2005 9:52 am
by shiznatix
preg_replace all < and > and everything inbetween them with just a blank space then just str_replace the top and bottom header things in the e-mail and you will be golden

Posted: Fri Jun 10, 2005 9:57 am
by tsg
Good idea, I will play with that.

Would you or anyone know by chance if all received emails follow the same message source format? Meaning if sent from outlook, or hotmail, yahoo, etc ... would they have the same format like the one I posted?

Thanks again
Tim

Posted: Fri Jun 10, 2005 9:59 am
by shiznatix
well e-mails like yahoo send the "do you yahoo" advertisment thing from the bottom. i would think if you could get the senders email address you would have a good idea if there is any extra crap that they are going to throw in then just preg_replace or str_replace the extra crap that would be in the e-mail body