>> Home > M5 PopMonger: Powerful Inbound Email Processing PopMonger Home | My Mach5 | Download | Support | Buy Popmonger  
Online Manual
PopMonger Links


Untitled Document

Explore M5 Mailer

Take the bulk out of email! TM

Use your own data
Personal email merge
Send individual email
HTML and/or text
Handy email templates


Explore M5 Subscriber

Web-based list management made simple!

Simple subscribe tool
Opt-in confirmed
Track reads and clicks
Custom matching look
Free for up to
        5000 contacts

 

PHP with PopMonger

The class definitions for PHP are:

PHP

  class object Popmonger
string HeaderText;
string BodyText;
string MessageText;
string FailedAddress;
string HeaderField($sHeader_name);
string Field($iFieldNumber);
int FieldsCount;
string MIMEPart($iPartNumber);
int MIMEPartsCount;
void RedirectMessage("sTo_address1,To_address2,To_address3");
void ReplyWithText($fsFom_address, $sSubject, $sReply_text);
void SendMail($from_address,$sTo_address,$sSubject_text,$sBody_text,$sEx_headers);
void SaveToFile($sFile_name, $sText_to_save, $bIsAppend);

PHP Examples:

  • Insert into Access

  • Iterate Excel

  • Helper Code for Debugging and Developing PHP scripts

  • Redirect to Multiple Addresses

  • Save Bounced Addresses

    • Insert into Access

      This script will insert an entry from PopMonger into a MS Access database using PHP:

      <?php

      $dbLocation = "C:\\databases\\mailing database.mdb"; //Database location

      $conn = new COM ("ADODB.Connection") //Create new ADO connection
      or die( "Cannot start ADO" );
      $conn->Open( "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=".$dbLocation ); //Open database

      $sSQL = "INSERT INTO table ( field1 , field2 ) VALUES( '".$popmonger->Field(0)."' , '".$popmonger->Field(1)."' )"; //Set SQL query

      $conn->Execute( $sSQL ); //Execute SQL query
      $conn->Close(); //Close database connection
      $conn->Release(); //Release resources for this connection

      ?>


      Back to Examples

      Iterate Excel

      <?php

      $dsn = "D:\\path\\to\\file\\test.xls";

      $conn = new COM ("ADODB.Connection")
      or die( "Cannot start ADO" );

      //Connect to the db
      $conn->Open( "Driver={Microsoft Excel Driver (*.xls)};DriverId=790;Dbq=".$dsn );

      //Execute query
      $query = "SELECT * FROM [Sheet1\$]";

      $rs = $conn->Execute( $query );

      $fld[0] = $rs->Fields(0);
      $fld[1] = $rs->Fields(1);

      while( !$rs->EOF ) {
      echo $fld[0]->name.": ".$fld[0]->value."\r\n";
      echo $fld[1]->name.": ".$fld[1]->value."\r\n";
      $rs->MoveNext();
      }

      $rs->close();
      $conn->Release();

      ?>


      Back to Examples

      Helper Code for Debugging and Developing PHP scripts

      The following code is very useful for developing PHP scripts, testing and debugging them. It is PHP5 compliant.

      <?php

      //coded for PHP 5
      /**
        * This class will define an object very similar to the Popmonger object returned by PopMonger 3 itself. This class
        * can be used for debugging purposes by modifying the fields near the top of the class. To use this class, 
        * either paste the following code into your script, or download the PopmongerClass.php file,
        * unzip it into the same directory as your Popmonger 3 script, and add the text  require('PopmongerClass.php'); 
        * to the top of your current PHP script.  If you are not running the script via apache or another web server, you may run
        * the script with the php.exe Command-Line interpreter.
       */

      class Popmonger { public $fields, $headers, $headerText, $bodyText, $messageText, $failedAddress, $mimeParts; public function __construct() { /** * Fields that would be returned by Popmonger 3 if the "Parse feedback using delimiters" box is checked in * the Actions tab of the Task options. */ $this->fields = array( "Robert" , "Smith" , "[email protected]" , "Oct" , "22" , "2006" ); /** * Headers that Popmonger 3 would return for this email. Note that this is an associative array, as is the * array returned by Popmonger 3. */ $this->headers = array( "subject" => "subject" , "from" => "from" , "to" => "to" ); /** * The raw header text for this email. */ $this->headerText = "Subject: ".$this->headers['subject']."\r\nFrom: ".$this->headers['from']."\r\nTo: ".$this->headers['to']; /** * The raw body text for this email. */ $this->bodyText = "This is the body which includes both HTML and TEXT portions if both were sent."; /** * The raw message text for this email. */ $this->messageText = "This is the raw message text which includes the ENTIRE MESSAGE, headers and all."; /** * The original sender address for created a bounced/failure address list. */ $this->failedAddress = "[email protected]"; /** * The MIME parts of this email, which would normally include any files attached. Feel free to use readfile() * here if you actually need to return a file for debugging purposes. */ $this->mimeParts = array( "file 1" , "file 2" , "file 3" ); } /** * This function will return the number of fields that have been successfully parsed by Popmonger 3 (in * this case, a count of the number of fields in the fields var array. * * @return - integer Number of fields parsed out of this email */ function FieldsCount() { return count( $this->fields ); } /** * This function will return the number of MIME parts in this email (in this case, a count of the number of * fields in the mimeParts var array. * * @return - integer Number of MIME parts in this email */ function MIMEPartsCount() { return count( $this->$mimeParts ); } /** * This function will return the message text associated with this email. * * @return - String message text */ function MessageText() { return $this->$messageText; } /** * This function will return the failed sender address associated with a bounced email. * * @return - String message text */ function FailedAddress() { return $this->$failedAddress; } /** * This function will return the header text associated with this email. * * @return - String header text */ function HeaderText() { return $this->$headerText; } /** * This function will return the body text associated with this email. * * @return - String body text */ function BodyText() { return $this->$bodyText; } /** * This function will return the i-th field associated with the email, based on the text that Popmonger 3 * parsed out. Note that this function does not perform any bounds-checking! Use the FieldsCount() function to * ensure that the index is within bounds. * * @param int - Field index to retrieve * * @return - String field value */ function Field( $i ) { return $this->fields[$i]; } /** * Send an email to this recipient. Note that this function does NOT actually send an email! It is only here * for debugging purposes. * * @param String - From: email address * @param String - To: email address * @param String - Subject of the email * @param String - Body of the email * @param String - Headers for this email */ function SendMail( $from , $to , $subject , $body , $headers ) { echo "Would have sent email to ".$to." from ".$from." with subject ".$subject."\r\n"; } /** * Redirect this message to another email address. Note that this function does NOT send email, it is only * here for debugging purposes. * * @param String - Email address to redirect this message to */ function RedirectMessage( $email ) { echo "redirecting this message to ".$email."r\n"; } /** * Reply to this message with this text. Note that thie function does NOT send email, it is only here for * debugging purposes. * * @param String - From: email address * @param String - Subject of the email * @param String - Text to reply with */ function ReplyWithText( $from , $subject , $replyText ) { echo "replying to ".$from." with subject ".$subject." and text ".$replyText."\r\n"; } /** * Save text to a file. * * @param String - Filename to write to * @param String - Text to write to this file * @param boolean - TRUE to append to a file, FALSE to truncate the file to 0 length and then write */ function SaveToFile( $filename , $text , $append ) { $write = 'w'; if( $append == TRUE || $append == '1' ) { $write = 'a'; } $fp = fopen( $filename , $write ); fputs( $fp , $text ); fclose( $fp ); } /** * Returns this header field. This would usually refer to the header fields parsed out by PopMonger, but * for debugging purposes returns the value of this element in the headers var array. * * @param String - Name of the header field to retrieve * * @return String - Value of this header field */ function HeaderField( $name ) { return $this->headers[$name]; } /** * Returns this MIME part of the email. This would usually refer to the MIME parts of the email, but for * debugging purposes returns the value of the mimeParts var array. * * @param integer - Index of the element to retrieve * * @return String - Value of this MIME part of the email */ function MIMEPart( $index ) { return $this->mimeParts[$index]; } } // End of Popmonger Class declaration //Instantiate a new popmonger object with the same name as the object returned by PopMonger itself. //$popmonger = new Popmonger(); //Confirmation that a PopMonger object was created. //echo "Made a new popmonger!";

      ?>


      Back to Examples

      Redirect to Multiple Addresses

      This script has been updated as Popmonger 3.0.48 and above can redirect to multiple email addresses natively. The use of multiple email redirection is demonstrated below.

      <?php
      
      $popmonger->RedirectMessage( "Email1,Email2,Email3" );
      //Multiple Emails are passed to Popmonger as a single string, with each address separated by commas
      
      ?>
      	

      The following script still works, but has been deprecated by new functionality in PopMonger 3.0.48 and above

      <?php

      $emails = array( "[email protected]" , "[email protected]" , "[email protected]" );

      for( $i = 0; $i < count( $emails ); $i++ ) {
      $popmonger->RedirectMessage( $emails[$i] );
      }

      ?>


      Back to Examples

      Save Bounced Addresses

      This example will save the failed address to a file "failures.txt", and then move to the next line. It will append any addresses to the list. Note that this example requires the PopMonger b17 or later.

      <?php

      $popmonger->SaveToFile( "failures.txt", $popmonger->FailedAddress."\r\n", 1 );

      ?>


      Back to Examples

    Home   |   Site map   |   Analyzer   |   Mailer   |   PopMonger   |   Resources   |   Customers and Partners  |   Contact
    Mach5 is a trademark of Mach5 Development, in use since 2000.