I've written this simple Perl code to extract the email addresses from a database and send an e-mail to each address individually using the standard Unix sendmail prog. However, when I run it, I get double e-mails everytime, to each address.
There are no duplicate e-mails in the database. I've tested the output of the loop and I don't get any duplicates -- but I get double e-mails in my inbox.
Any thoughts?
$marc
#SUBROUTINE SENDS E-MAILS
sub sendEmail {
# the body of the e-mail and the subject are
# read from an incoming array
($emailHTML,$subject) = @_;
# read all the e-mail addresses from the database
my $request = $dbh->prepare("SELECT email from emaildatabase where job = 'test' order by location");
$request->execute();
while (($email) = $request->fetchrow) {
push @indata,"$email";
}
for ($j=0;$j<=$#indata;$j++) {
open (MAIL, "|$mailprog -t -oi") || die "Can't open mail program\n";
print MAIL "To: $indata[$j] \n";
print MAIL "From: myemailaddress@domain.com\
n";
print MAIL "Subject: $subject\n";
print MAIL "MIME-Version: 1.0\n";
print MAIL "Content-type: text/html;\n\n";
print MAIL $emailHTML;
print MAIL "\n\n";
close MAIL;
}
}
Start Free Trial