Extracting information from email using php

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
Razorsharp87
Forum Newbie
Posts: 2
Joined: Wed Jun 03, 2009 6:04 am

Extracting information from email using php

Post by Razorsharp87 »

I have a situation whereby people would send me their information using email. The process is pretty similar with each email. Thus, I was thinking if its possible to make it automated, to have a script to extract information from my email, process it accordingly and do the appropriate actions. My question would be, is there a way to extract information from an email using php? Or any other programming languages? Thanks!

P.S I'm using hotmail now. Is there any email providers that makes this process easier?
User avatar
mikemike
Forum Contributor
Posts: 355
Joined: Sun May 24, 2009 5:37 pm
Location: Chester, UK

Re: Extracting information from email using php

Post by mikemike »

Using regualr expression (regexp) would be your best bet, I suggest Googling for some tutorials on it.

However, fi you're using Hotmail I don't see how you can get PHP to access the mails (easily).
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Re: Extracting information from email using php

Post by alex.barylski »

Sure, attach the data as CSV and open the email using IMAP functions, extract the attachment, voila...it's done all the time...
User avatar
mikemike
Forum Contributor
Posts: 355
Joined: Sun May 24, 2009 5:37 pm
Location: Chester, UK

Re: Extracting information from email using php

Post by mikemike »

I don't think that's what he's after. I'm assuming you want to extract the body of the email and use parts of it for soemthing?
Razorsharp87
Forum Newbie
Posts: 2
Joined: Wed Jun 03, 2009 6:04 am

Re: Extracting information from email using php

Post by Razorsharp87 »

Hi guys! Thanks for your input. I would check out "regexp" soon. And yeah what mikemike said is right. I would like to extract the body part of the email to do certain process for feedback.
User avatar
mikemike
Forum Contributor
Posts: 355
Joined: Sun May 24, 2009 5:37 pm
Location: Chester, UK

Re: Extracting information from email using php

Post by mikemike »

You're going to have issues with hotmail, I've never known any API to interact with it - although don't quote me on that as I haven't used anything to do with Hotmail since I was about 12 (a good 10 years ago now :().

If you must use your hotmail account perhaps you could forward your mail elsewhere using a tool by Hotmail ? Not sure if they offer this...
User avatar
kaisellgren
DevNet Resident
Posts: 1675
Joined: Sat Jan 07, 2006 5:52 am
Location: Lahti, Finland.

Re: Extracting information from email using php

Post by kaisellgren »

What is the problem we are solving here?

You can read it easily with IMAP like already stated: http://fi.php.net/manual/en/function.imap-body.php
User avatar
mikemike
Forum Contributor
Posts: 355
Joined: Sun May 24, 2009 5:37 pm
Location: Chester, UK

Re: Extracting information from email using php

Post by mikemike »

So far as I can tell the problem isn't grabbing the email body, it's extracting set blocks of information from a string, which in this case happens to be an email. Grabbing the email content itself isn't the problem. Also, that link you posted isn't what was proposed earlier (not by you) I don't think, as the previous post was talking about attaching the data as a CSV, which I'm not sure was what was being described.

If he could show us a few example emails perhaps we could help him with the string matching...
paulcobb
Forum Newbie
Posts: 4
Joined: Thu May 28, 2009 1:21 pm

Re: Extracting information from email using php

Post by paulcobb »

Hi All,

I have an almost working script using PHP to access an IMAP email box and forward on to an SMS gateway any emails that match the filter.

The script is working but have one minor issue re decoding the subject.

See Post: viewtopic.php?f=1&t=100909

Many thanks

Paul
Post Reply