tags:

views:

342

answers:

6

I want to send data to an emailaddress and save it into a MySQL database (PHP). What is the easiest way to do this? (no form post, no curl etc., just email)

+3  A: 

If you can access the email using POP just have a process checking the email with POP functions and sending everything to your database

Also you could use php IMAP support

victor hugo
I already have access and I take your solution in account. But the server account has no cron capabilities.
Tom Schaefer
Without cron, I see no way to do it, other than using another server that does have cron to call the php script or a custom mail server, that would call the script.
Nico Burns
Do you mean the server hasn't cron capabilities because it is in a hosting service?
victor hugo
Not the server. I do not have access to setup a cron job.
Tom Schaefer
Yes, it is a hosting service.
Tom Schaefer
+2  A: 

Assuming you know how to save the data to mysql already, you will need access to a mail server, either your own, a webhosts, or you could use a free one such as Gmail, or Hotmail.

You can then use PHP's IMAP functions (which can access POP too) to access the mail. Articles which may help you with this: PHP imap info and a tutorial on creating PHP webmail

Nico Burns
Dear Nico, thanks for the alternative.
Tom Schaefer
+5  A: 

there are a few ways.

  • use a postfix alias script, basically, postfix receives your mail, and then runs it through a script of your choosing. The contents of the mail appear in STDIN - then you can do as you please with the contents of the mail.

  • Use a custom mail server like apache james, that is designed to process mail, and 'do something with it'

{A good one I found recently was in the google labs - http://freshmeat.net/projects/subethasmtp} - looked really good.

pls bear in mind that email is not a guaranteed protocol, if you are trying to do app-to-app messaging, then there are probably better ways!

Hope this helps., ace

phatmanace
For my actual problem I do not see a way to involve it. :-( But many thanks for the hint. For other setups this will work.
Tom Schaefer
if you are using the subetha one, you would write two classs, a custom message factory and a custom message handler. When the server receives a mail, it creates one of the handler objects, and effectiley passes you the datastream of the message object. you then use MimeMessage and Session to decode this into an object that you can do what you like with. in your case, extract fields and put in a database. I got an example up and working in about 1 hour. it was a very well thought out framework.
phatmanace
It seems that found a neat way which is very interesting for the community. Would be nice if you share it.
Tom Schaefer
+1  A: 

There is a slicehost step-by-step tutorial that takes a unix based machine, installs postfix on it, sets it up to use MySQL and configures it to accept virtual users and serve/receive email from multiple domains.

The set up is clean, fast and secure. Life is good, eh?

http://articles.slicehost.com/email

deau
Many thanks for your advice. I'll take it in account.
Tom Schaefer
+3  A: 

If your server doesn't have imap but you have an outside system which does have cron you can write a page that checks the email account and loads the data into MySQL then set up a script on a machine that does have cron to wget the mysql page once every X minutes where X is how frequently you want to load data.

Alternately if you know the emails will load quickly you can set up small one field table in your DB with a time stamp. Each time your PHP script runs it checks the time stamp and if it's more than 5 minutes old it calls the email loading script before loading the web page.

Dennis Baker
hahaha, that's the idea. Hey Dennis, you make my day.
Tom Schaefer
+1 I was just editing my answer to add the check-email-per-page idea
victor hugo
see it as a bonus for your job ;_)
Tom Schaefer
A: 

Perhaps you should look at www.dbmail.org