SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    May 2005
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Piped Email Wierd Problem

    Hello,

    I sure could use a bit of guidance on this one.

    I am piping email from Outlook Express & Web Mail to a php app that scans in the mail and puts it in a datbase. I have two seperate domains with seperate web sites. I am running this scanner (identical) on both.

    If I email the support address on the first domain, the scanner takes the piped email and does exactly what it is supposed to do.

    If I email the second support address to the second domain, the scanner appears to be doing the same thing except one big problem. After I send the Outlook Express email to this scanner, instead of getting back one notification that the scan worked ok , I get back almost 1000 of these "worked ok" messages.

    I have checked and double checked the code, the pipe statement, etc. I am running both sites on CPanel on the same server. I am stumped ! Anyone have any suggestions at all ?

  2. #2
    SitePoint Addict
    Join Date
    Aug 2004
    Location
    Chicago
    Posts
    296
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If we could see the code, it'd probably help...
    Why's (Poignant) Guide to Ruby
    learn ruby with foxes, wizards, and chunky bacon

  3. #3
    SitePoint Member
    Join Date
    May 2005
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry about that...duh.

    Here it is....

    #!/usr/bin/php -q
    <?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
    $date = "";
    $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];
    }
    // look out for special headers
    if (preg_match("/^Date: (.*)/", $lines[$i], $matches)) {
    $date = $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;
    }
    }

    include ('config.php');
    include ('defaults.php');
    include ('escapeq.php');
    include ('email_strip.php');

    // Check the above email 'from' string for MIME format.
    $from = strip_email_from($from);

    $subject = safe_escape_string($subject);
    $message = safe_escape_string($message);

    $sql = "INSERT INTO emailqueue SET fromaddress='$from', datex='$date', subject='$subject', body='$message'";

    if (@mysql_query($sql)) {
    mail (EMAIL , 'Incoming Support Request', 'Check your AHD Email Queue for details');
    } else {
    mail( EMAIL, 'Error writing support request', mysql_error());
    }

    ?>


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •