PDA

View Full Version : Email to MySQL Database - PHP?



LMS16
04-02-2011, 09:07 AM
Hey,

Is there a way that Im able to send an email to a certain email address then get a PHP script to connect to it a extract the separate data and insert it into a database?

+REP

Lew.

Johno
04-02-2011, 02:00 PM
I believe it's possible, have a look here http://us2.php.net/manual/en/ref.imap.php to see the IMAP functions and then it's simply a case of storing it into the database.

LMS16
04-02-2011, 02:23 PM
So,

This would be a case of using imap_open() to open the imap stream, then read the body with imap_body()

Then get the script to seperate different things within the body to insert them into the database?

Example:

Email to: [email protected]

Body:

Engineer : #Lewis#
Customer Reference : #CTI34d3r5f#
Quote Reference : #QU4tgfS2#
Job Category : #1#
Job Type : #2#
Job Description : #RANDOM JOB!#
Equipment : #Additional Equip#

Then get PHP to separate he values between the #'s?

Sounds easy enough, Ill have a look into it, if anyone could suggest a way to do it, would be appreciated

Lew.

Dentafrice
05-02-2011, 04:09 PM
Check this out:

http://www.phpclasses.org/package/3324-PHP-Retrieve-e-mail-messages-into-a-MySQL-database.html

I've never used this class but it seems to do what you want. You can modify it enough to make it work I believe.

Remember when you're exploding / separating your data in the body, to always clean it... don't want someone to commit SQL injection through your e-mail form ;)

LMS16
05-02-2011, 11:34 PM
Check this out:

http://www.phpclasses.org/package/3324-PHP-Retrieve-e-mail-messages-into-a-MySQL-database.html

I've never used this class but it seems to do what you want. You can modify it enough to make it work I believe.

Remember when you're exploding / separating your data in the body, to always clean it... don't want someone to commit SQL injection through your e-mail form ;)

Indeed, although Ill be using it at work an no1 has a clue about opening a php tag let alone a sql injection :P

Lew.

Want to hide these adverts? Register an account for free!