Files:

\n"; /* This is the correct way to loop over the directory. */ while (false !== ($file = readdir($handle))) { if($file=='.' || $file=='..') continue; echo "$file
\n"; } closedir($handle); } echo "

Download source code"; exit; } echo "

Attempts to parse Multipart reports for hard bounces, according to RFC1892 (RFC 1892 - The Multipart/Report Content Type for the Reporting of Mail System Administrative Messages) and RFC1894 (RFC 1894 - An Extensible Message Format for Delivery Status Notifications). We can reuse this for any well-formed bounces.

"; echo "

Here is the parsed head

\n"; $head_hash = BounceHandler::parse_head($head); echo "
";
print_r($head_hash);
echo "
"; if (BounceHandler::is_RFC1892_multipart_report($head_hash) === TRUE){ print "

Looks like an RFC1892 multipart report

"; } else { print "

Not an RFC1892 multipart report

"; exit; } echo "

Here is the parsed report

\n"; echo "

Postfix adds an appropriate X- header (X-Postfix-Sender:), so you do not need to create one via phpmailer. RFC's call for an optional Original-recipient field, but mandatory Final-recipient field is a fair substitute.

"; $boundary = $head_hash['Content-type']['boundary']; $mime_sections = BounceHandler::parse_body_into_mime_sections($body, $boundary); $rpt_hash = BounceHandler::parse_machine_parsable_body_part($mime_sections['machine_parsable_body_part']); echo "
";
print_r($rpt_hash);
echo "
"; echo "

Here is the error status code

\n"; echo "

It's all in the status code, if you can find one.

"; for($i=0; $iReport #".($i+1)."
\n"; echo BounceHandler::get_recipient($rpt_hash['per_recipient'][$i]); $scode = $rpt_hash['per_recipient'][$i]['Status']; echo "
$scode
"; echo BounceHandler::fetch_status_messages($scode); echo "

\n"; } echo "

The Diagnostic-code

is not the same as the reported status code, but it seems to be more descriptive, so it should be extracted (if possible)."; for($i=0; $iReport #".($i+1)."
\n"; echo BounceHandler::get_recipient($rpt_hash['per_recipient'][$i]); $dcode = $rpt_hash['per_recipient'][$i]['Diagnostic-code']['text']; if($dcode){ echo "

$dcode
"; echo BounceHandler::fetch_status_messages($dcode); } else{ echo "
couldn't decode
"; } echo "

\n"; } echo "

Grab original To: and From:

\n"; echo "

Just in case we don't have an Original-recipient: field, or a X-Postfix-Sender: field, we can retrieve information from the (optional) returned message body part

\n"; $head = BounceHandler::get_head_from_returned_message_body_part($mime_sections); echo "

From: ".$head['From']."
To: ".$head['To']."
Subject: ".$head['Subject']."

"; echo "

Here is the body in RFC1892 parts

\n"; echo "

Three parts: [first_body_part], [machine_parsable_body_part], and [returned_message_body_part]

"; echo "
";
print_r($mime_sections);
echo "
"; /* $status_code = BounceHandler::format_status_code($rpt_hash['per_recipient'][$i]['Status']); $status_code_msg = BounceHandler::fetch_status_messages($status_code['code']); $status_code_remote_msg = $status_code['text']; $diag_code = BounceHandler::format_status_code($rpt_hash['per_recipient'][$i]['Diagnostic-code']['text']); $diag_code_msg = BounceHandler::fetch_status_messages($diag_code['code']); $diag_code_remote_msg = $diag_code['text']; */ ?>