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:
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!
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!