Gossamer Forum
Home : Products : DBMan : Customization :

mass mailer sending duplicates

Quote Reply
mass mailer sending duplicates
suddenly the mass mailer hack is sending two copies of email to each person. i've added two hacks to the hack --

one that sends an email to admin every time the mass mailer is used. this includes the email message as well as a list of the email addresses to which the mass mail was sent.

the other pulls an unsubscribe message from the cfg file and adds it at the end of each email

i've looked at my code and can't see a problem. here's the sub from db.cgi:

Code:

sub mass_mail {
# --------------------------------------------------------
#
my ($i,$message,@lines,$line,$count,%rec,$mail_count);
unless ($admin_email) { $message = "Admin email has not been entered in the .cfg file<BR>"; }
unless ($admin_email =~ /^[A-Z0-9._%-]+\@[A-Z0-9.-]+\.[A-Z]{2,4}$/i) { $message = "Admin email address is not in the correct format.<BR>"; }
unless ($in{'subject'}) { $message .= "You must fill in a subject for your message.<BR>"; }
unless ($in{'emailmessage'}) { $message .= "Your email message is empty.<BR>"; }
for ($i = 0; $i <= $#db_cols; $i++) {
if ($db_email_field eq $db_cols[$i]) {
$found = 1;
last;
}
}
if (!$found) {
$message .= "email field not found<BR>";
}
open (DB, "<$db_file_name") or &cgierr("error in mass_mail. unable to open database: $db_file_name.\nReason: $!");
@lines = <DB>;
close DB;
$in{'mh'} = $#lines;
my ($status, @hits) = &query("view");
unless ($status eq 'ok') {
$message .= "$status<BR>";
}
if ($message) {
chomp($message);
&html_mass_mail_form($message);
return;
}
my ($numhits) = ($#hits+1) / ($#db_cols+1);
for (0 .. $numhits - 1) {
%rec = &array_to_hash($_, @hits);
if ($rec{$db_email_field} =~ /.+\@.+\..+/) {
open (MAIL, "$mailprog") || &cgierr("unable to open mail program");
print MAIL "To: $rec{$db_email_field}\n";
print MAIL "From: $admin_email\n";
print MAIL "Subject: Mail from $html_title\n\n";
print MAIL "-" x 75 . "\n\n";
print MAIL "Subject: $in{'subject'}\n\n";
print MAIL "From: $in{$db_cols[12]}\n\n";
print MAIL $in{'emailmessage'};
if ($unsubscribe) {
print MAIL "\n\n";
print MAIL "-" x 25 . "\n\n";
print MAIL "$unsubscribe\n";
}
close (MAIL);
++$mail_count;
push (@sent_to,$rec{$db_email_field}); # hack to collect the email addresses
}
}
# hack to send copy to admin
open (MAIL, "$mailprog") || &cgierr("unable to open mail program");
print MAIL "To: $admin_email\n";
print MAIL "From: $admin_email\n";
print MAIL "Subject: Massmail $html_title\n\n";
print MAIL "-" x 75 . "\n\n";
print MAIL "Subject: $in{'subject'}\n\n";
print MAIL $in{'emailmessage'};
print MAIL "\n\n";
print MAIL "-" x 25 . "\n\n";
print MAIL "Message sent to: \n"; # hack to send email addresses to admin
foreach $usersent (@sent_to) {
print MAIL "$usersent\n";
}
close (MAIL);
&html_mass_mail_success($mail_count);
}

can anyone help find my problem or tell me where else to look? thanks!
Quote Reply
Re: [delicia] mass mailer sending duplicates In reply to
There's nothing I could see in the code that would send things out twice. Is there any chance that you're calling the subroutine twice? That's the only thing I can think of.


JPD
----------------------------------------------------
JPDeni's DBMan-ual
How to ask questions the smart way.
Quote Reply
Re: [JPDeni] mass mailer sending duplicates In reply to
i can't find it being called twice. the only place is see mass_mail being called is the submit button in sub html_mass_mail_form.

update:

user error!!! i had set up a dummy record with permission to send mass mail. that record had an email address that was being forwarded to me and the person who was sending the mass mail. of course, both of us had a regular record too. so we were the only ones receiving duplicate. i hacked the script to send emails only to validated records (unless admin) and that should take care of problem.

Last edited by:

delicia: May 13, 2006, 6:26 AM