• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 224
  • Last Modified:

PHP for mail spools

Hello!

I have an interesting problem...

Currently, there is a web script that is automatically sending me an email each time one of my products is purchased online.  These emails contain two things...the email of the purchaser, and a software key they use to unlock the software.

The user gets a copy of this email as well, so they get all of the necessary information. That part is just fine.

But what I am left with is a gigantic list of emails that contain the "welcome" email for each user.  As you can imagine this is a customer support nightmare..each time somebody loses their key, we have to go and sift through the emails to find their particular email, send them their key, etc.

What I need is to create a PHP script that I will put on a cron...it will check this email address when ran (which is on the same domain server by the way), go through the emails in that email address inbox, pull out the email address of the user and the software key, and dump them into a database.

I have already coded the database part...all of that I can handle.

The only problem I am having is that I don't know how to access a local mail inbox with my PHP script.  Once I get in and loop through the emails, I can take care of the rest.  I just don't know how to access the mail spool with my PHP script.

Is there a simple way to do this? A library perhaps?

Thank you all for any help you can provide!

-Kevin
0
ProjectZIG
Asked:
ProjectZIG
1 Solution
 
Tyler LaczkoCommented:
You could most likely look into the squirrel mail software. It does it...
0
 
Ray PaseurCommented:
I would use an "email pipe" for this.  It can access your data base.  A pipe script is started every time an email is received, so there is no need to go into a mailbox.  Here is an example of one I have used as a demonstration script.  Your moving parts will start around line 55.
#!/usr/bin/php -q
<?php // /email_pipe/index.php


// THIS IS AN EMAIL PIPE SCRIPT.
// THIS SCRIPT IS STARTED AUTOMATICALLY FOR EACH MESSAGE.
// NOTE THAT THIS SCRIPT IS ABOVE THE /public_html/ DIRECTORY TO PREVENT ACCIDENTAL EXECUTION


// --> HOW DO WE KNOW WHICH EMAIL MESSAGES GET SENT HERE?
// THIS SCRIPT RECEIVES MESSAGES SENT TO email_pipe@your.org
// CREATE AN EMAIL MAILBOX EXCLUSIVELY FOR AUTOMATED PROCESSING.
// SET UP AN EMAIL FORWARD FOR THAT MAILBOX IN cPANEL->EMAIL LIKE THIS:
// 1...5...10...15...20...25...
// |/home/{account}/email_pipe/index.php


// --> WHEN YOU UPLOAD, THIS SCRIPT WILL BE MARKED RW-R-R BUT THAT IS WRONG
// THIS SCRIPT MUST BE MARKED EXECUTABLE x0755
// YOU CAN USE FTP SOFTWARE TO CHMOD TO RWX-RX-RX


// --> NOTE THE FIRST LINE OF THIS SCRIPT MUST SAY #!/usr/bin/php -q STARTING IN COLUMN ONE
// 1...5...10...15...20...25...
// #!/usr/bin/php -q
// <?php ... PROGRAM CODE FOLLOWS


error_reporting(E_ALL);

// USE THE OUTPUT BUFFER - THIS DOES NOT HAVE BROWSER OUTPUT
ob_start();

// COLLECT THE INFORMATION HERE
$raw_email = '';


// TRY TO READ THE EMAIL FROM STDIN
if (!$stdin = fopen("php://stdin", "R"))
{
    echo "ERROR: UNABLE TO OPEN php://stdin \n";
}

// ABLE TO READ THE MAIL
else
{
    while (!feof($stdin))
    {
        $raw_email .= fread($stdin, 4096);
    }
    fclose($stdin);
}


// REMOVE MULTIPLE BLANKS - AND OTHER PROCESSING AS MIGHT BE NEEDED
$raw_email = preg_replace('/ +/', ' ', $raw_email);

// SPEW WHAT WE GOT, IF ANYTHING, INTO THE OUTPUT BUFFER
var_dump($raw_email);

// CAPTURE THE OUTPUT BUFFER AND SEND IT TO SOMEONE ELSE VIA EMAIL
$buf = ob_get_contents();
mail ('you@your.org', 'EMAIL PIPE DATA', $buf);
ob_end_clean();

Open in new window

0
 
ProjectZIGAuthor Commented:
Perfect :) Exactly what I needed.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now