Click to See Complete Forum and Search --> : Insert Emailed Information into a Database Automatically
ardesigns
September 11th, 2010, 02:16 PM
Hi. I'm not so sure if this falls into the category of server-side scripting (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 (server-side script or not), or if it's possible at all?
Thanks,
ARDesigns
PeejAvery
September 11th, 2010, 05:48 PM
Yes, it can be done with most server-side scripting languages. PHP and PERL are two good options. Here's (http://www.devarticles.com/c/a/PHP/Incoming-Mail-and-PHP/1/) a good PHP tutorial on setting it up through various methods.
ardesigns
September 11th, 2010, 06:03 PM
Thanks a lot for that link! The tutorial was very helpful and exactly what I was looking for.
Only one last thing:
How can I use PHP to parse the $message variable (which holds the body of the email) so that the text after, but on the same line as, "Name: " that is "name" and then a colon, and then a space, are saved into the variable $name ?
Also, how can I check to make sure that $message contains the word "name:" , and, if it doesn't, to exit the script?
Thanks a lot,
ARDesigns
PeejAvery
September 11th, 2010, 06:26 PM
Regular Expressions (http://www.php.net/manual/en/ref.pcre.php)
ardesigns
September 12th, 2010, 02:48 PM
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 (I know I just said "one more thing," but I promise this is the last thing!) 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!
PeejAvery
September 14th, 2010, 03:36 PM
You'll have to parse the attachment data out...once again using those regular expressions. For each attachment there will be boundary header data and then content headers.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.