arwebdesign Posted September 11, 2010 Share Posted September 11, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/213170-insert-emailed-information-into-a-database-automatically/ Share on other sites More sharing options...
BizLab Posted September 11, 2010 Share Posted September 11, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/213170-insert-emailed-information-into-a-database-automatically/#findComment-1109993 Share on other sites More sharing options...
fortnox007 Posted September 11, 2010 Share Posted September 11, 2010 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) Quote Link to comment https://forums.phpfreaks.com/topic/213170-insert-emailed-information-into-a-database-automatically/#findComment-1109994 Share on other sites More sharing options...
arwebdesign Posted September 11, 2010 Author Share Posted September 11, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/213170-insert-emailed-information-into-a-database-automatically/#findComment-1109997 Share on other sites More sharing options...
arwebdesign Posted September 11, 2010 Author Share Posted September 11, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/213170-insert-emailed-information-into-a-database-automatically/#findComment-1110054 Share on other sites More sharing options...
fortnox007 Posted September 11, 2010 Share Posted September 11, 2010 yep that is possible. But I am no expert on that. You would need regular expressions for it if I am correct. or explode() or something Quote Link to comment https://forums.phpfreaks.com/topic/213170-insert-emailed-information-into-a-database-automatically/#findComment-1110055 Share on other sites More sharing options...
BizLab Posted September 12, 2010 Share Posted September 12, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/213170-insert-emailed-information-into-a-database-automatically/#findComment-1110240 Share on other sites More sharing options...
arwebdesign Posted September 12, 2010 Author Share Posted September 12, 2010 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! Quote Link to comment https://forums.phpfreaks.com/topic/213170-insert-emailed-information-into-a-database-automatically/#findComment-1110319 Share on other sites More sharing options...
Hypnos Posted September 13, 2010 Share Posted September 13, 2010 You should be able to use base64_decode() but I would sooner use a MIME class from PEAR or somewhere. Quote Link to comment https://forums.phpfreaks.com/topic/213170-insert-emailed-information-into-a-database-automatically/#findComment-1110418 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.