0
votes

I use PHPMailer-BMH for tracking bounced messages because I develop bulk email system with php. I tested it with gmail server. Script connects on server and list all mails from inbox. I send email on bad address and google mail returns Delivery Status Notification. Here is one example of output.

2:--Mail Delivery [email protected] | unrecognized | none | not deleted | Mail Delivery Subsystem | Delivery Status Notification (Failure)hhhhh:
3:--Mail Delivery [email protected] | unrecognized | none | not deleted | Mail Delivery Subsystem | Delivery Status Notification (Failure)hhhhh:

For this I use callbackAction above.

function callbackAction ($msgnum, $bounce_type, $email, $subject, $xheader, $remove, $rule_no=false, $rule_cat=false, $totalFetched=0) {

  if ( $remove == true || $remove == '1' ) {
    echo "note: sample code would have set the database to allowed='false'<br />";
  }
  $displayData = prepData($email, $bounce_type, $remove);
  $bounce_type = $displayData['bounce_type'];
  $emailName   = $displayData['emailName'];
  $emailAddy   = $displayData['emailAddy'];
  $remove      = $displayData['remove'];

  echo $msgnum . ':--'.$emailName. "---" .$emailAddy. "--". $rule_no . ' | '  . $rule_cat . ' | '  . $bounce_type . ' | '  . $remove . ' | ' . $email . ' | '  . $subject . "hhhhh:" . $xheader . "<br />\n";


  return true;
}

Scripts displays undelivered messages but I can not get bad email address, because I need to delete bad addresses from database. How you can see for email scripts returns [email protected]. this is not the mail that I have sent the message on. Is there solution to get bad email address?

1

1 Answers

0
votes

You need to use a callback.

function callbackAction ($msgnum, $bounce_type, $email, $subject, $xheader, $remove, $rule_no=false, $rule_cat=false, $totalFetched=0)
{
    $cleanEmail = someFunctionToSanitize($email);
    $sql = "DELETE FROM yourTable WHERE emailAddress = '" . $cleanEmail . "'";

    // call your function to execute the query here.
    // this is a simple example, using bound parameters in the query would be better
}

If you want to use a different function name, then you must let the BounceMailHandler object know.

$bmh = new BounceMailHandler();
$bmh->action_function    = 'someNewFunctionName'; // default is 'callbackAction'