Jump to content

Insert Emailed Information into a Database Automatically


arwebdesign

Recommended Posts

Hi. I'm not so sure if this falls into the category of php (since I'm not even remotely sure how to do this), but I'd like to set up an email address, that, when it receives an email, automatically inserts the contents of that email into a database (for example, if the email is:

 

name: Bob

phone: 5556667777

 

Then it would enter "Bob" into the "name" column of a new row, and "5556667777" into the "phone" column of that same row.

 

Does anybody know how I can go about doing this (php or not), or if it's possible at all?

 

Thanks,

ARWebDesign

 

Link to comment
Share on other sites

Is the info coming in from a website? If so, you can just enter the info directly into the DB. Otherwise, you have quite a project on your hands. If there is anyway to direct these communications to a web form and then use the form to submit to a DB you will save yourself a head of hair.. lol

Link to comment
Share on other sites

well I am wondering why you want this first off all : ) aren't there better ways for this. And what happends if someone finds out this e-mailaddress and sents bogus info? Isn't an online form not a nicer and cleaner solution with less room for error?

Anyway, I think this can only be achieved if the emails all have a very specific format. That way i am pretty sure there are php functions, that could figure out what parts are new info and know to which variable they should assign it. How? I haven't got a clue yet (I am still a novice)

Link to comment
Share on other sites

Yes, it's true that a web form would be easier, but most of the info will be sent by email and it'd be a lot easier to be able to quickly format the email, and then forward it to a "listener" email address, especially because the emails will include attachments (and it's a lot easier to forward an attachment than to download then re-upload).

 

Can this be done with PHP? How would I direct the PHP to "listen" to the inbox of an email address?

 

Thanks again.

Link to comment
Share on other sites

I have found a tutorial that does what I was looking for (here: http://www.devarticles.com/c/a/PHP/Incoming-Mail-and-PHP/1/ if anyone's interested), but I have one last question:

 

the script provided in the tutorial saves the contents of the body of the email in the variable $message . How can I use PHP to parse $message so that the text after the word "Name: " (that is "name" and then a colon, and then a space), but on the same line as "Name: " is saved into the variable $name ?

 

For instance, if the email was:

 

"Hello, blah blah blah.

Name: Example Name

Blah Blah Blah"

 

then the PHP script would save the text "Example Name" into the variable $name .

 

Alternatively, if this is not possible, could I make the script parse the $message variable and simply save the first line of the variable into $name ?

 

Thanks,

ARWebDesign

Link to comment
Share on other sites

The CGI methods for PHP, SHELL access, and all the other parts of that tutorial are quite technical operations, good luck! I would like to note that the article was written in 2003 for a depreciated version of PHP... so you will need to translate that to PHP5 or 6. If you want to continue look into: http://php.net/manual/en/function.preg-match.php

Link to comment
Share on other sites

Hi, thanks for all the replies! I've now got the system working:

when I email that email address with:

 

blah blah blah

Name: Bob

Blah Blah Blah

 

it inserts "Bob" into the database. My last hurdle here is how to deal with attachments. As I understand it, attachments are stored as a MIME string in the actual MIME data. How can I parse the data out of the raw MIME data that is sent to the PHP file, and then decode the attachment and save it to my server?

 

Thanks!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.