View Full Version : Useage of PHP's Mailparse Functions

11-29-2010, 10:16 PM
I am building a PHP based helpdesk ticketing system, yes I know there are lots of them already made, but I am specifically making this as a plugin to my CMS, Wordpress, for which is is no viable and affordable option that I could find.

For the most part this is fairly straight forward, the one thing giving me problems is I have to allow users to send an email and generate a ticket from that. I plan of having my web server pipe the incoming emails to a PHP script, this is easy enough to do with cPanel. And I use standard input to receive the message, now I am looking to parse it into its parts, while looking for a way to do this the best option I could find is Mailparse, the problem is I have no clue how to use it, and PHP's documentation isn't any help. I could really use some actual code examples of this in action to help out.

What I need to do to the incoming email is this:

* Get the From Address, To Address, and Subject from the headers
* Use substring on the Subject to get the ticket id (for replies to existing tickets)
* Identify the user the ticket is for using the From Address
* Identify the department the ticket is for using the To Address
* Obtain the plan-text version of the email body (if there is only an html version I do have a class I can use to strip out the html and make a plain-text version)
* Ignore any quoted text in the email body, and focus on the new text which will be the content for the ticket.

So what I need help doing using Mailparse is obtaining the header information and message body, and stripping out the previous quotes message(s) from the body to get just the new reply.

Any help would be greatly appreciated, Thanks in Advance.