I have a form which stores data into an array. When I do a test print on the array @mails, it prints out the email addresses that are inside. The array can have anywhere between 1 and 5 email addresses as these are form fields.
However, later down the script I have the following snippet and it FAILS. Even if the test print above shows there are email addresses in the array, it fails and prints
failed.
failed.
failed.
failed.
failed.
The emails have been delivered.
Is there something wrong with the conditionals or how I am using $mails[$cnt]? I can't put my finger on what's causing this.
Code:
my $fmail1 = param("fmail1");
my $fmail2 = param("fmail2");
my $fmail3 = param("fmail3");
my $fmail4 = param("fmail4");
my $fmail5 = param("fmail5");
my @mails = qq($fmail1 $fmail2 $fmail3 $fmail4 $fmail5);
foreach(@mails) { print "$_<p>"; }
However, later down the script I have the following snippet and it FAILS. Even if the test print above shows there are email addresses in the array, it fails and prints
failed.
failed.
failed.
failed.
failed.
The emails have been delivered.
Is there something wrong with the conditionals or how I am using $mails[$cnt]? I can't put my finger on what's causing this.
Code:
for my $cnt (1 .. 5)
{
if ($mails[$cnt] ne "")
{
open(MAIL,"| $sendmail") or die "Can't open $sendmail sendmail because: $!";
print MAIL "To: $mails[$cnt]\n";
print MAIL "From: $email\n";
print MAIL "Subject: Refer A Friend from $names[$cnt]\n\n";
print MAIL "Dear $names[$cnt],\n\n";
print MAIL "Your friend, $name at $email, visited out site recently and thought you would be interested..\n\n";
print MAIL "This is NOT spam. This email was sent by someone who said they knew you. Your email address is not stored in any databases and will not
be sold or given to anyone at any time. This is the only time you will receive an email from us.";
close(MAIL);
}
else
{
print "$mails[$cnt] failed.<br>";
}
}