Code Monkey home page Code Monkey logo

emilhauk / php-bounce-handler Goto Github PK

View Code? Open in Web Editor NEW

This project forked from rmast/php-bounce-handler

0.0 0.0 0.0 1.81 MB

This class can be used to parse bounced message reports. It parses e-mail messages with multipart report content type formatted according to RFC 1892 and 1894 documents. If the bounce is not well formed, it also tries to extract some useful information. Exim is supported, partially. Please send bounce messages from your busted MTA, I'll extend the class to support them. It can extract the the address of the recipient that bounced as well the mail server response status code.

PHP 82.12% Roff 17.88%

php-bounce-handler's Introduction

Quick and dirty bounce handler

Usage

require_once('bounce_driver.class.php'); $bouncehandler=new Bouncehandler(); $multiArray=$bouncehandler->get_the_facts(\$strEmail)

( $multiArray=$bouncehandler->get_the_facts($strEmail) can be replaced by $multiArray = $bouncehandler->parse_email($strEmail) )

Returns a multi-dimensional associative array of bounced recipient addresses and their SMTP status codes (if available) - see print_r(\$multiArray);

Will return recipient's email address, the RFC1893 error code, and the action. Action can be one of the following:

transient
Temporary problem
failed
Permanent problem
autoresponse
Vacation auto-response/auto-responder
""
Empty string - not classified

You could dereference the $multiArray in a 'for loop', for example...

    foreach($multiArray as $the){
        switch($the['action']){
            case 'failed':
                //do something
                kill_him($the['recipient']);
                break;
            case 'transient':
                //do something else
                $num_attempts  = delivery_attempts($the['recipient']);
                if($num_attempts  > 10){
                    kill_him($the['recipient']);
                }
                else{
                    insert_into_queue($the['recipient'], ($num_attempts+1));
                }
                break;
            case 'autoresponse':
                //do something different
                postpone($the['recipient'], '7 days');
                break;
            default:
                //don't do anything
                break;
        }
    }

Or, if it is an FBL, you could use the class variables to access the data (Unlike Multipart-reports, FBL's report only one bounce) You could also use them if the output array has only one index:

    if($bouncehandler->type == 'fbl'
       or count($bouncehandler->output) == 1)
    {
        echo $bouncehandler->action;
        echo $bouncehandler->status;
        echo $bouncehandler->recipient;
        echo $bouncehandler->feedback_type;
    }

These class variables are safe for all bounce types:

  • $bouncehandler->type
  • $bouncehandler->subject
  • $bouncehandler->web_beacon_1
  • $bouncehandler->web_beacon_2
  • $bouncehandler->x_header_beacon_1
  • $bouncehandler->x_header_beacon_2

That's all you need to know, but if you want to get more complicated you can. Most methods are public. See source code.

php-bounce-handler's People

Contributors

rbairwell avatar rmast avatar filsh avatar cfortune avatar emilhauk avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.