Tring Web Design

Specialist Web Designers in the Tring Area, Berkhamsted, Bucks and Herts - info@tring-web-design.co.uk

Pipe emails into a PHP script

  • Resources
  • cPanel Website Backups
  • Creating dynamic PDF files from PHP
  • Download Limit Monitoring Using IPCOP
  • Encrypt USB drives
  • E-Mail Newsletter Design
  • Exclude my visits from Google Analytics
  • Extract, Transform and Load
  • Forum Posts
  • Glossary of Terms
  • Imaging Hard Drives
  • Installing IPCOP as a firewall
  • PHP-GTK SWK Desktop Widgets
  • Pipe emails into a PHP script

  • Pure Rounded CSS3 Corners
  • SEO Basics
  • Speed up Xubuntu Boot Time
  • Sphider Tag Cloud
  • Static header and footer from dynamic templates
  • Suckerfish CMS Made Simple menus
  • Top of Google in 5 steps
  • Website Morphing
  • Watch
  • Music & Effects
  • Syslog Firewall Analysis
  • Tools
  • This little snippet will catch emails sent to a specific address, allowing you to then do any sort of manipulation on it. I successfully used it for over a year processing over 700 emails a day, extracting information from the email and inserting into a MySQL database. The script then produced a PDF document using the R&OS Class. Setup a forwarder and instead of an email address, put in the code in quotes below. This was easy to do in cPanel. I found this snippet on the internet somewhere, I cant remember exactly where.

    #!/usr/bin/php -q
    <?php

    /*
    You may need to play with chmod on this file
    targetemail@yourdomain.co.uk, "|/usr/bin/php -q /home/user/public_html/this-script.php"

    */


    $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;
    }
    }

    $message;

    /* do any further processing down here */

    ?>

    New to content management or need some help using our system? View our video tutorials

    E-mail us or complete our requirements questionnaire for a more detailed quote

    Technical resources for web designers, developers and IT professionals

    Keep up-to-date with the projects we have been involved in

    Specialist web designers in Tring, Berkhamsted, Bucks and Herts
    © Oliver Partridge trading as Tring Web Design

    info@tring-web-design.co.uk