我使用PHPMailer-BMH来跟踪退回邮件,因为我使用php开发批量电子邮件系统。我用gmail服务器测试了它。脚本在服务器上连接并列出收件箱中的所有邮件。我发送错误地址的电子邮件和谷歌邮件返回交付状态通知。这是输出的一个例子。
2:--Mail Delivery Subsystem---mailer-daemon@googlemail.com--0000 | unrecognized | none | not deleted | Mail Delivery Subsystem | Delivery Status Notification (Failure)hhhhh:
3:--Mail Delivery Subsystem---mailer-daemon@googlemail.com--0000 | unrecognized | none | not deleted | Mail Delivery Subsystem | Delivery Status Notification (Failure)hhhhh:
为此,我使用上面的callbackAction。
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;
}
脚本显示未传递的邮件但我无法收到错误的电子邮件地址,因为我需要从数据库中删除错误的地址。如何查看电子邮件脚本返回daemon@googlemail.com。这不是我发送邮件的邮件。是否有解决方案来获取错误的电子邮件地址?
答案 0 :(得分:0)
您需要使用回调。
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
}
如果要使用其他函数名称,则必须知道BounceMailHandler
对象。
$bmh = new BounceMailHandler();
$bmh->action_function = 'someNewFunctionName'; // default is 'callbackAction'