Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    May 2005
    Posts
    224
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Automatic mysql update upon email being recieved

    Is there any way to automatically grab the from field from an email, and use it to run a mysql command based on who the email is from?

    Right now, I have to manually get the from name and run it through a simple form to update my mysql columns. Is there any way to automate this?

  • #2
    New Coder
    Join Date
    Jan 2007
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts
    What do you mean? Explain better.

  • #3
    Regular Coder
    Join Date
    May 2005
    Posts
    224
    Thanks
    1
    Thanked 0 Times in 0 Posts
    1) User Sends Email
    2) I recieve email
    3) I take everything before the @ in their email address
    4) I change a column value in mysql relating to their email address

    How can I automate this?

  • #4
    Senior Coder
    Join Date
    Jan 2007
    Posts
    1,648
    Thanks
    1
    Thanked 58 Times in 54 Posts
    If you let PHP have access to the email in some way or another (stored as text file) you could basically filter out the From: header using a regular expression:

    PHP Code:
    $matches = array();
    preg_match("/^From:(.+)$/"$email$matches);
    if (
    sizeof($matches)) $email $matches[1]; 
    I'm not 100% positive this would work. But I don't see why not.

    The easiest way to run this code would be to have a directory with all new emails.

    Then use crontab to run this script every X minutes. The script could read all files in a folder, and use the above code to figure out the From address.

    Then afterwards delete everything in that directory for the next run.
    Last edited by aedrin; 01-25-2007 at 05:10 PM.

  • #5
    Regular Coder
    Join Date
    May 2005
    Posts
    224
    Thanks
    1
    Thanked 0 Times in 0 Posts
    My host saves emails in files named like this:

    1169686720.M751482P10797V0000000000000303I0040C43F_0.caprica.sslcatacombnetworking.com,S=1194:2,S
    But if I open it in notepad it's just the email+headers.

    Is there a way to get PHP to read that?


  •  

    Posting Permissions

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