Jump to content

[SOLVED] Process incoming email via php??


schilly

Recommended Posts

Is there a way to process incoming email to the mail server and pass it off to php for processing? I am looking to set up a support ticket system. the biggest shortfall right now is how to process the replies from the clients. any help or ideas is greatly appreciated.

 

thx.

Link to comment
Share on other sites

It is called "pipe email to php script"

It is not a very well known way of doing things, and not even google could help me with that.

I am fairly new to php and found my answer looking at the open source "eticket" system and how they do it...

 

If you use their pipe to email script will you save yourself a lot of trouble...

 

Let me know if you need more help!

 

Stefan

Link to comment
Share on other sites

Do you have a dedicated server?

I grabbed their script installed the system and modified the pipe script they r using.

 

I must warn you! This is not an easy task to tackle!!!

Best is to download the eticket system, install it and see how they parse the email....

 

I bet this will be your easiest way in winning this task!

Link to comment
Share on other sites

If you are lucky enough to have CPanel on your server account you can create a new email where the script will be mailed to and create a "Email Account Forwarders" for that email account.

 

The forwarder look something like this:

Address  Forward To 

pipemail@domain.com  |/home/thehost/public_html/online/ticket/pipe.php

 

Forget about what ever you found on google about pipe email to php script as I have found NO solution that work!

 

What do you want to use this script for?

Link to comment
Share on other sites

it's going to be used for a ticket system.

 

ok i finally got it working. for anyone using qmail, this is how i did it

 

-create new mailbox in plesk/web interface

-log in through shell

-open /var/qmail/mailnames/domain.com/mailbox_username/.qmail

-add | /full/path/to/script/script.php on a new line

restart qmail: /etc/init.d/qmail restart

make sure script file is 755 perms (chmod if needed)

 

email will be delivered to the mailbox as well as the script

 

php script:

#!/usr/bin/php
<?php

// read from stdin
$fd = fopen("php://stdin", "r");
$email = "";
while (!feof($fd)) {
    $email .= fread($fd, 1024);
}
fclose($fd);

// handle email
$lines = explode("\n", $email);

// empty vars
$from = "";
$subject = "";
$headers = "";
$message = "";
$splittingheaders = true;

for ($i=0; $i < count($lines); $i++) {
    if ($splittingheaders) {
        // this is a header
        $headers .= $lines[$i]."\n";

        // look out for special headers
        if (preg_match("/^Subject: (.*)/", $lines[$i], $matches)) {
            $subject = $matches[1];
        }
        if (preg_match("/^From: (.*)/", $lines[$i], $matches)) {
            $from = $matches[1];
        }
    } else {
        // not a header, but message
        $message .= $lines[$i]."\n";
    }

    if (trim($lines[$i])=="") {
        // empty line, header section has ended
        $splittingheaders = false;
    }
}

//test email to make sure it works
mail('email@domain.com',"Testing Email Piping","Headers: $headers\n\n\n Message: $message");

?>

do not send the test email to the same account. i should have known better. infinite loop. 1000 emails in the span of a few mins.

 

as Stefan said it can probably be done through your web interface as well but I didn't have access to it so had to go through shell.

 

hope this helps anyone else looking to do this.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.