I have looked and debugged, and debugged some more. I cannot figure out why my script is sending two copies of the email at a time.
Any suggestions?
(email function is towards the bottom)
Thanks!
[...]
<?
}
//sending a saved campaign
else if ($mode == "send")
{
//pull info about this campaign
$cid=$_GET["cid"];
$sql="SELECT * FROM email_campaigns WHERE id=".$cid;
$result=get_mysql_result($sql);
$row = mysql_fetch_array($result,MYSQL_ASSOC);
$name=$row["name"];
$grouprecipients=explode(",",$row["recipient_groups"]);
$subject=$row["subject"];
$text=$row["email_text"];
$launch_date=$row["launch_date"];
$template=$row["template"];
$template_images=explode("|",$row["template_images"]);
$recipients=Array();
//**********************************************************
// GET RETAIL USERS BELONGING TO ANY OF THE GROUPS
//**********************************************************
foreach ($grouprecipients as $group)
{
$sql="SELECT email FROM email_list WHERE egroup='".$group."'";
$rs=get_mysql_result($sql);
while ($row=mysql_fetch_array($rs,MYSQL_ASSOC))
{
//add this recipient to the array of recipients
array_push($recipients,$row["email"]);
}
}
//**********************************************************
// GET WHOLESALE USERS BELONGING TO ANY OF THE GROUPS
//**********************************************************
foreach ($grouprecipients as $group)
{
$sql="SELECT wholesaler_email FROM wholesalers WHERE wholesaler_group='".$group."' OR wholesaler_group2='".$group."'";
$rs=get_mysql_result($sql);
while ($row=mysql_fetch_array($rs,MYSQL_ASSOC))
{
//add this recipient to the array of recipients
array_push($recipients,$row["wholesaler_email"]);
}
}
//remove any duplicates in the array due to adding group recipients
$recipients = array_unique($recipients);
//update recipients of this email campaign
//by setting their status to 'active' and appending this campaign
//to their current list of campaigns
$update="UPDATE email_list SET status='Active',campaigns=CONCAT(campaigns,',".addslashes($name)."') WHERE ";
$count=0;
foreach ($recipients as $recipient)
{
if ($recipient != "")
{
if ($count == 0)
$update=$update."email='".$recipient."'";
else
$update=$update." OR email='".$recipient."'";
$count++;
}
}
get_mysql_result($update);
//------------------------------------------
// SEND EMAIL
//------------------------------------------
/* To send HTML mail, you can set the Content-type header. */
$headers = "MIME-Version: 1.0\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\n";
//$headers .= "Content-Transfer-Encoding: base64\r\n\r\n";
//additional headers
$headers .= "From: domain <info@domain.com>\n"."\Reply-To: info@domain.com\n"."X-Mailer: PHP\Return-Path:bounced-mail@domain.com";
//$headers .= chunk_split(base64_encode($message));
$message=build_email($template,$template_images,$text,$subject);
// and now mail it
$recipients = array_unique($recipients);
foreach ($recipients as $emailaddress)
{
//echo'Email Sent To - '.$emailaddress.'<BR>';
//$this_header=$headers."\nTo: ".$emailaddress;
mail($emailaddress, $subject, $message, $headers,"-t -f bounced-mail@domain.com");
}
?>
<Script language="javascript">location.href='manageCampaigns.php?done=2';</script>
<?
}
?>
</table>
</form>
[...]