Web Hosting Talk







View Full Version : Parsing an email with PHP


jherbison
10-28-2007, 03:54 PM
I am trying to create an email script that pulls emails with IMAP, seperate the parts and put each part into a different variable to be submitted to a MySql database.

I am having 2 problems.
1. Trying to actually pull a readable section of the message. Each time I get the following message. I was wanting to pull just the quoted-printable section or whatever section I need to. All I get for the body of the message is:

Message: This is a multipart message in MIME format. ------=_NextPart_000_0019_01C8195F.A8391580 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit This is a test email sent from outlook. ------=_NextPart_000_0019_01C8195F.A8391580 Content-Type: text/html; charset="us-ascii" Content-Transfer-Encoding: quoted-printable
This is a test email sent from outlook.

------=_NextPart_000_0019_01C8195F.A8391580--

I can't figure out how to pull just the message part.

The second thing that I am having problems with is attachments, but I will work on that once I get the message section fixed.

Thanks,
jherbison

Jamie Edwards
10-28-2007, 03:56 PM
This is a pretty neat class that does MIME parsing: http://www.phpclasses.org/browse/package/3169.html

chenetwork
10-28-2007, 04:57 PM
I am trying to create an email script that pulls emails with IMAP

You are better off sending the emails directly to the script as opposed to making your script check an existing IMAP account if possible. Let's pretend the email address is support @ something dot com. Setup an alias so that all email to support @ something dot com gets forwarded to /path-to-PHP SCRIPT-NAME. Notice there is a space between the path to PHP and the name of the script.

This bypasses the need to write extra code in the PHP script to actually check an email account and you can focus on coding just the parsing of the email.

jherbison
10-29-2007, 12:14 PM
Connecting to the IMAP or POP3 server isn't the problem. I can connect, its just separating the heades... I still get

------=_NextPart_000_000C_01C8195C.6CBCD760 Content-Type: text/html; charset="us-ascii" Content-Transfer-Encoding: quoted-printable

included with the body of the message..