A common practice of tracking the success of mailing operations is to use the "Return-Path" header of an email.
Example of an email and its header:
Return-Path: server@return.xyz.com
Received: from localhost (mx-1-1 [127.0.0.1])
by mx-1.xyz.com (Postfix) with ESMTP id 3F81556754
for <jbradler@xyz.com>; Wed, 2 May 2012 12:27:18 +0200 (CEST)
To: jbradler@xyz.com
Subject: test mailing
From: Jens <jbradler@xyz.com>
Message-Id: <20120502102717.763ADA88004@xyz.com>
Date: Wed, 2 May 2012 12:27:17 +0200 (CEST)
Hi Folks, ...
Whereby the "From" header is your choice of real name and email address that you want the reader to see, the primary purpose of the "Return-Path" is to designate the address to which messages indicating non-delivery or other mail system failures are to be sent ([see RFC 2821 for more details][1]).
So basically this header is the right position to start fetching non-delivery reports.
How I would do this:
- create a unique subdomain to fetch all non-delivery reports (e.g. return.xyz.com)
- set-up a inbox to catch all emails sent to the above subdomain (regardless of the local part of the email address, e.g. *@return.xyz.com)
- make emails unique => one recipient one unique email (no use of BCC)
- use recipient id (e.g. numeric id of your recipient data base) and email or campaign id to generate the local part of the future (e.g. {campaign_id}-{recipient_id})
- use new Return-Path: Return-Path: {campaign_id}-{recipient_id}@return.xyz.com
- create some tools to fetch incoming mail and filter out real non-delivery reports from SPAM and temporary notifications (e.g. out-of-office messages)
Here an example with a unique Return-Path:
Return-Path: 123-456@return.xyz.com
Received: from localhost (mx-1-1 [127.0.0.1])
by mx-1.xyz.com (Postfix) with ESMTP id 3F81556754
for <jbradler@xyz.com>; Wed, 2 May 2012 12:27:18 +0200 (CEST)
To: jbradler@xyz.com
Subject: test mailing
From: Jens <jbradler@xyz.com>
Message-Id: <20120502102717.763ADA88004@xyz.com>
Date: Wed, 2 May 2012 12:27:17 +0200 (CEST)
Hi Folks, ...
That's it.
Edit - How to implement that via phpMailer:
/* define domain name for non-delivery reports */
define('RETURN_PATH_DOMAIN', 'return.xyz.com');
/* get current campaign id */
$campaignId = 123;
/* loop recipient list and send email */
foreach ($array as $userId => $user) {
try{
$mail = new PHPMailer();
$mail->HeaderLine('Return-Path', $userId . '-' $campaignId . '@' . RETURN_PATH_DOMAIN);
$mail->To($user['email'], $user['customerName']);
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!";
$mail->AddReplyTo("noreply@company.com","Company Name");
$mail->SetFrom('noreply@company.com', 'Company Name');
$mail->Subject = "Company| E-Zine";
$mail->MsgHTML($ezineContent);
if(!$mail->Send()) {
// show log
} else {
//show successful msg
}
} catch (Exception $e) {
// show error
}
}
As far as I remember we had problems by using the local sendmail. The header Return-Path was replaced by some configurations of the local MTA. If this is the case try to use SMTP to a usable relay host instead.