Page 1 of 1
Extracting information from email using php
Posted: Wed Jun 03, 2009 6:09 am
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?
Re: Extracting information from email using php
Posted: Wed Jun 03, 2009 10:15 am
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).
Re: Extracting information from email using php
Posted: Wed Jun 03, 2009 11:34 am
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...
Re: Extracting information from email using php
Posted: Wed Jun 03, 2009 12:10 pm
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?
Re: Extracting information from email using php
Posted: Thu Jun 04, 2009 1:49 pm
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.
Re: Extracting information from email using php
Posted: Thu Jun 04, 2009 2:25 pm
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...
Re: Extracting information from email using php
Posted: Thu Jun 04, 2009 6:03 pm
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
Re: Extracting information from email using php
Posted: Thu Jun 04, 2009 6:06 pm
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...
Re: Extracting information from email using php
Posted: Mon Jun 08, 2009 11:00 am
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