View Full Version : Pipe email to PHP script to be parsed

11-27-2010, 02:08 PM
I am looking to pipe emails sent to an address at a specific subdomain to a php script, my control panel (cPanel) has an option to pipe such emails to a php script. I just need help finding examples on how to retreive the email contents piped to my script and how to parse the email to make a MySQL entry for it. Specifically I am working on developing a help desk system and i will need to seperate the sender, subject, and email body (ignoring any quoted contents of the body) to create a ticket in my db.

Any idea where I can find a function or class to do this. I need it to be GPL v2 or a compatible license as the code will be used in a project I am developing that I will release as GPL v2.


11-27-2010, 05:56 PM
Basically you need to use fopen() to read from the special "stdin" wrapper. Something like this should work:

$fp = fopen("php://stdin","r");
$email_data = '';
while ( $line = fgets($fp) ) {
$email_data .= $line

//$email_data should now contain the piped-in input

11-28-2010, 02:42 AM
WHat I need is good well written open source code that can do this for me. I am not looking to build my own from scatch. THeir is no need to reinvent the wheel here so to speak and it would be rather difficult to do so. Plus I would have no clue how to deal with diffrent types of encoding anf MIME types.

Thus I am just looking for something that already does that for me.