Hey Gurus
I just can’t see anything about the loop in this script that would cause an extra email to be generated for each row in the recordset. As usual, I’m pretty nervous about exposing my self-taught coding. All the includes but one are for page formatting; that one is PHPMailer, and maybe it’s doing something I don’t know about. I have verified that everybody gets the email twice. Any ideas?
[code=php]<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN”>
<html>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=iso-8859-1″>
<title>Washington Workforce Association – Send E-Letter (test)</title>
<meta name=”author” content=”Washington Workforce Association”>
<link rel=”stylesheet” href=”http://www.washingtonworkforce.org/styles/style.css” type=”text/css”>
<?php require(“/usr/www/users/washing3/includes/embed_menu_style.inc”);
// open the DB
$connx = connect_db(“washing3_SupportersWWA”) or die(“Unable to connect to database.”);
// set a timestamp variable, for WA user local time
$dateTime = date(‘Y-m-d H:i:s’,mktime(date(“H”)-3, date(“i”), date(“s”), date(“m”) , date(“d”), date(“Y”)));
// start code for display
print ‘</head><body bgcolor=”#FFFFFF”>’;
require(“/usr/www/users/washing3/includes/start_prof_page.inc”);
require(“/usr/www/users/washing3/cgi-bin/phpmailer/class.phpmailer.php”);
$text = makeHTMLBody($_GET[‘ID’]);
$altText = makeTextBody($_GET[‘ID’]);
$sqlSupp = ‘SELECT * FROM tblSupporters WHERE pkSupporters = ‘.$_GET[‘testID’].’;’;
$qrySupp = mysql_query($sqlSupp);
while ($rowSupp = mysql_fetch_array($qrySupp)) {
if ($rowSupp[‘Email’]) {
if (sendELetter($text, $altText, $rowSupp[‘Email’], $rowSupp[‘FName’].’ ‘.$rowSupp[‘LName’])) {
$num+= 1;
} // end if
else {
$numFlubbed += 1;
} // end else
} // end if
} // end while
mysql_free_result($qrySupp);
print ‘<h2>E-Newsletter Confirmation Page</h2><hr size=”3″ color=”#0000B7″>’;
if ($num>1) $plural = ‘s’;
print $num.’ email’.$plural.’ sent…’;
if ($numFlubbed) print ‘but ‘.$numFlubbed.’ emails failed.’;
require(“/usr/www/users/washing3/includes/end_page.inc”);
//————————————————————————————————————
function sendELetter($body, $altBody, $email, $name) {
$mail = new PHPMailer();
$mail->IsSMTP(); // send via SMTP
$mail->Host = “******”; // SMTP servers
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = “******” // SMTP username
$mail->Password = “******”; // SMTP password
$mail->From = “[email protected]”;
$mail->FromName = “WWA Supporters”;
$mail->AddReplyTo(“[email protected]”,”WWA Supporters”);
$mail->WordWrap = 70; // set word wrap
$mail->IsHTML(true); // send as HTML
$mail->Subject = “Washington Workforce Association E-Newsletter”;
$mail->Body = $body;
$mail->AltBody = $altBody;
$mail->AddAddress($email, $name);
if($mail->Send()) return True;
} // end function
//————————————————————————————————————
function makeHTMLBody($update) {
//(abridged for forum)
} //end function
//————————————————————————————————————
function makeTextBody($update) {
//(abridged for forum)
} //end function
//————————————————————————————————————
function validateAddress($address) {
//(abridged for forum)
} //end function
//—————————————————————————————————-
mysql_close($connx);
?>