/    Sign up×
Community /Pin to ProfileBookmark

loop sending email twice to each recipient – why?

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);
?>[/code]

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@NogDogSep 08.2007 — First thing I'd do is run the query whose results you are looping on to see if it is returning multiple instances of the same email addresses. If so, perhaps you'll want to do a SELECT DISTINCT... query?
Copy linkTweet thisAlerts:
@strBeanauthorSep 10.2007 — I thought about it, even tried adding DISTINCT to the query (still got 2 in my test) but then I realized: my loop also counts iterations, and the number it prints on my confirmation page is the right number, as if duplicates had not been sent. Doesn't this suggest that there is something going on that I don't understand in the PHPMailer class?

This is a bit urgent - I have a communication that has to go out to this list early today. They'll have to each get 2 if I can't figure out how to make it only send 1.
×

Success!

Help @strBean spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...