Mail Queue problem - when sending to multiple email addresses, headers only use first address

From: Date: Fri, 21 Jan 2011 15:19:05 +0000
Subject: Mail Queue problem - when sending to multiple email addresses, headers only use first address
Groups: php.pear.general 
Request: Send a blank email to pear-general+get-30926@lists.php.net to get a copy of this message
Hi. I am working on a broadcast email system for site users. The list of names/email addresses is loaded into PHP, then I go through every entry in the email list and use $mail_queue->put to add it to the database. The recipient field works correctly, but the headers field always stays the same using the data from the first user. So I end up with multiple rows of data in the mail_queue table, the recipient is always different as it should be, but headers is the exact same data for every recipient including the TO field, so every recipient receives the email but on analyzing the header only sees it addressed to the first person on the list, thus making their email address public. Here is the code I use: // initialize MIME $mime = new Mail_Mime(); $mime->setHTMLBody($msg_body_html); $mime->setTXTBody($msg_body_text); $body = $mime->get(); // end initialize MIME $mail_queue = new Mail_Queue($db_options, $mail_options); $sql = "call pListRecipients(" . $msg_list . ")"; $rs = ExecSql($sql); while ($result = $rs->fetch_assoc()) { if($result['fldFullName'] != '') $msg_to = $result['fldFullName'] . "<" . $result['fldEmail'] . ">"; else $msg_to = $result['fldEmail']; $hdrs = array( 'From' => $msg_from, 'To' => $msg_to, 'Subject' => $msg_subject ); $hdrs = $mime->headers($hdrs); $mail_queue->put($msg_from, $msg_to, $hdrs, $body); } This always happens for the first email in this loop - when I start a new loop, it keeps the header for that loop the same. I experimented with this. I added $x and $x++ into the while loop and added $x to $msg_subject on each loop, so each email should have a different subject. Still the entire header in each database entry used the same subject. I used var_dump just before put, so I know that the data on my end is created correctly. The only way I found so far to create a workaround for this was to take the initialize MIME block and place it inside the while loop - then everything works. I also tried unset($hdrs) before assigning the array without success. Is this normal behavior? Do I really have to initialize the MIME object on every while run, or is there something else I'm missing? I looked at the pear PHP code and couldn't find anything there that would explain this, but then I've only worked with PHP for about 6 months, so I might be missing something simple here... Thanks in advance for any help you can give me! cu, Richard

« previous php.pear.general (#30926) next »