Specifications

LISTING 28.15 Continued
$result = mysql_query($query);
if(!$result)
echo “<p>Error getting subscriber list”;
$count = 0;
// for each subscriber
while( $subscriber = mysql_fetch_row($result) )
{
if($subscriber[2]==’H’)
//send HTML version to people who want it
$mail->send($subscriber[0], $subscriber[1], $from_name,
$from_address, $subject);
else
//send text version to people who don’t want HTML mail
mail($subscriber[0].” <”.$subscriber[1].”>”, $subject,
$text, “From: $from_name <$from_address>”);
$count++;
}
$query = “update mail set status = ‘SENT’, sent = now()
where mailid = $mailid”;
if(db_connect())
{
$result = mysql_query($query);
}
echo “<p>A total of $count messages were sent.”;
}
else if($status == ‘SENT’)
{
echo “<p>This mail has already been sent.”;
}
}
}
This function does several different things.
It test mails the newsletter to the administrator before sending it. It keeps track of this by track-
ing the status of a piece of mail in the database. When the upload script uploads a piece of
mail, it sets the initial status of that mail to STORED.
If the send() function finds that a mail has the status STORED, it will update this to
TESTED and send it to the administrator. The status TESTED means the newsletter has
been test mailed to the administrator. If the status is TESTED, it will be changed to SENT
and sent to the whole list.
Building a Mailing List Manager
C
HAPTER 28
28
BUILDING A
MAILING LIST
MANAGER
707
34 7842 CH28 3/6/01 3:46 PM Page 707