Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8945159
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T12:11:10+00:00 2026-06-15T12:11:10+00:00

Working on a project that requires incoming email to be parsed, and certain information

  • 0

Working on a project that requires incoming email to be parsed, and certain information be extracted and stored in the database. We’re using postmarkapp to extract the body content of the email so we only have the text only guts of it, but I’m currently a bit stuck on how to parse the email the most efficient way.

Over time we’ll be adding more ‘accepted’ formats of incoming mail, but to start off with we’ll have probably 4 common emails coming in, that is, they’ll follow the same format and the information that we want to extract (contact details, id’s, links, bio) will be in the same place, (per supported format).

I’m thinking that we’ll have an interface that will handle the common tasks, and each supported format will implement that, however just how to get that information is where I’m stuck.

Open to any thoughts and ideas on different methods / technologies to do this, ideally PHP, but if we need to use something else, that’s fine.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T12:11:11+00:00Added an answer on June 15, 2026 at 12:11 pm

    There is a similar feature on a site that I developed. Our users get emails from their suppliers with pricing. They copy and paste the body of the email into a textarea on our site and click a button. Then we parse the text to find products and prices and stick the info into a database.

    To do the parsing, we first have to determine the supplier, like you’ll need to do to determine which template was used. We look for certain strings in the text – the supplier’s name usually, or a line that’s unique to their emails. We do that in a method called something like getParserForText(). That method returns a Parser object which implements a simple interface with a parseText() method.

    There’s a Parser implementation class for each format. The parseText() method in each class is responsible for getting the data out of the text. We looked for ways of making these elegant and generic and have simply not found a really good way to do that. We’re using a combination of regular expressions, splitting the string into smaller sections, and walking through the string.

    Pseudocode:

    $text = $_POST['emailBody'];
    $parser = getParserForText($text);
    $result = $parser->parseText($text);
    if(count($result["errors"]) > 0)
    {
        // handle errors
    }
    else
    {
        saveToDatabase($result["prices"]);
    }
    

    We have no control over the formats the suppliers use, so we have to resort to things like:

    1. split the text into an array of strings around each line with a date (prey_split())

    2. for each element in that array, the first line contains the date, the next three to six lines contain products and prices

    3. pull the date out and then split the string on new lines

    4. for each line, use a regex to find the price ($000.0000) and pull it out

    5. trim the rest of the line to use as the product name

    We use a lot of prey_split(), preg_match_all() and explode(). While it doesn’t seem to me to be particularly elegant or generic, the system has been very robust. By leaving a little wiggle room in the regular expressions, we’ve made it through a number of small format changes without needing to change the code. By “wiggle room” I mean things like: Don’t search for a space, search for any whitespace. Don’t search for a dollar sign and two numbers, search for a dollar sign and any number of numbers. Little things like that.

    EDIT:

    Here’s a question I asked about it a few years ago:
    Algorithms or Patterns for reading text

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on a project that requires to convert html email into text. Below
I'm working on a C# XNA project that requires me to display information based
I am working on a project that requires JDBC Calls to an Oracle Database.
I am working on a project that requires me to define a DSL. Since
I'm working on a project that requires a fair bit of inserting/updating rows in
I am working on a project that requires some image processing. The front end
Currently am working on a project that requires me to create some XML for
I'm working on a project that requires me to programmatically create MySQL users from
I'm working on a project that requires a Web-based workflow application. We're now evaluating
I am currently working on a project that requires me to display PDF documents

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.