CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Sep 2010
    Posts
    3

    Insert Emailed Information into a Database Automatically

    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

  2. #2
    Join Date
    May 2002
    Posts
    10,943

    Re: Insert Emailed Information into a Database Automatically

    Yes, it can be done with most server-side scripting languages. PHP and PERL are two good options. Here's a good PHP tutorial on setting it up through various methods.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  3. #3
    Join Date
    Sep 2010
    Posts
    3

    Re: Insert Emailed Information into a Database Automatically

    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

  4. #4
    Join Date
    May 2002
    Posts
    10,943

    Re: Insert Emailed Information into a Database Automatically

    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  5. #5
    Join Date
    Sep 2010
    Posts
    3

    Re: Insert Emailed Information into a Database Automatically

    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!

  6. #6
    Join Date
    May 2002
    Posts
    10,943

    Re: Insert Emailed Information into a Database Automatically

    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.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured