Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mail to MySQL Database

Tags:

php

email

mysql

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)

like image 893
Tom Schaefer Avatar asked Jul 17 '09 23:07

Tom Schaefer


2 Answers

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

like image 89
phatmanace Avatar answered Nov 15 '22 07:11

phatmanace


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.

like image 43
Ogre Codes Avatar answered Nov 15 '22 07:11

Ogre Codes