Multiple bounced email adresses in one message

Questions on using the Simple Mailing List

Multiple bounced email adresses in one message

Postby daveoshay » Thu Mar 04, 2010 2:16 pm

Hi, Great script! My server returns all bounced addresses in a single email message. The following code in member.php will only advance the bounce count number of the first address it finds before deleting and expunging the message. It appears that the code is written to look for one email address per bounced message. Is there an easy mod to make the while loop find and advance the bounce number of all addresses in one message? Thanks!

Code: Select all
if($config['check_bounces'])
{
   $mbox = imap_open("{localhost:143/imap/notls}", $config[bounce_mailbox], $config[bounce_password]);

   $headers = imap_sort($mbox,SORTDATE,1);

   while (list ($key, $val) = each ($headers))
   {
      $body = imap_body ($mbox, $val);
      preg_match("/[A-z0-9][\w.-]*@[A-z0-9][\w\-\.]+\.[A-z0-9]{2,6}/i",$body,$matches);

      $bounce_query = "UPDATE mailinglist_subscribers SET bounce_count = bounce_count + 1 WHERE address = '$matches[0]'";
      $bounce_result = mysql_query($bounce_query) or die("Query failed : " . mysql_error());

      imap_delete($mbox,$val);
   }

   imap_expunge($mbox);
   imap_close($mbox);
}


Only finds bogus2@jiuythgf.org
Code: Select all
This message was created automatically by mail delivery software.

A message that you sent could not be delivered to one or more of its
recipients. This is a permanent error. The following address(es) failed:

  bogus2@jiuythgf.org
    The mail server could not deliver mail to bogus2@jiuythgf.org.  The account or
domain may not exist, they may be blacklisted, or missing the proper dns
entries.
  bogus1@jkirritr.org
    The mail server could not deliver mail to bogus1@jkirritr.org.  The account or
domain may not exist, they may be blacklisted, or missing the proper dns
entries.
  bogus3@kklopoik.org
    The mail server could not deliver mail to bogus3@kklopoik.org.  The account or
domain may not exist, they may be blacklisted, or missing the proper dns
entries.
daveoshay
 
Posts: 2
Joined: Thu Mar 04, 2010 1:42 pm

Re: Multiple bounced email adresses in one message

Postby daveoshay » Mon Mar 15, 2010 11:15 am

I changed preg_match to preg_match_all hoping for the best but now NO bounces are counted. Oh well, my search for a solution continues. :?
daveoshay
 
Posts: 2
Joined: Thu Mar 04, 2010 1:42 pm

Re: Multiple bounced email adresses in one message

Postby rage » Tue Apr 06, 2010 7:19 pm

Hey daveoshay,

I wrote you a fix.

replace:
Code: Select all
      preg_match("/[A-z0-9][\w.-]*@[A-z0-9][\w\-\.]+\.[A-z0-9]{2,6}/i",$body,$matches);
      
      $bounce_query = "UPDATE mailinglist_subscribers SET bounce_count = bounce_count + 1 WHERE address = '$matches[0]'";
      $bounce_result = mysql_query($bounce_query) or die("Query failed : " . mysql_error());


with:
Code: Select all
      preg_match_all("/[A-z0-9][\w.-]*@[A-z0-9][\w\-\.]+\.[A-z0-9]{2,6}/i", $body, $matches);
      
      $matches = array_unique($matches[0]); // Remove dupes and make uni-dimensional
      
      foreach($matches as $mvalue) { // Process all the addresses
      
         $bounce_query = "UPDATE mailinglist_subscribers SET bounce_count = bounce_count + 1 WHERE address = '$mvalue'";
         $bounce_result = mysql_query($bounce_query) or die("Query failed : " . mysql_error());
         
      }


Cheers
rage
 
Posts: 4
Joined: Fri Feb 12, 2010 5:32 pm


Return to Using Simple Mailing List (SML)

Who is online

Users browsing this forum: No registered users and 1 guest

cron