You didn't describe what your problem was. What happens? What's the error? It will help if you add
use warnings;
use strict;
to the start of your code. This will enable warnings and force you to declare your variables, which greatly aids in catching mistakes.
Now, on the topic of your code: You're trying to send an email with one very long list of recipients. It's possible your email server will not honor this. You may want to try sending one email/address, like so (code UNTESTED):
use strict;
use warnings;
# Define constants
my $address_file = "email.txt";
my $message_text = "message.txt";
my $from_addr = "anywhere@home.com";
my $mailhost = "localhost";
# Always check to see if file opened or not
open(MSG, "$message_text") || die "Could not open $message_text! $!\n"
+;
my $subject;
my $body;
LINE: while(<MSG>) {
if /^subject:(.*)/ { $subject = $1 and next LINE};
$body .= $_;
}
close(MSG);
open(LIST, "$address_file") || die "Could not open $address_file! $!\n
+";
# Send an email for each address in the file
# Note we're not doing any validation on addresses
while(<LIST>) {
chomp;
my $sender = Net::SMTP->new("$localhost");
$sender->mail("$from_addr");
$sender->to("$_");
$sender->data();
$sender->datasend ("From: Home\n");
$sender->datasend ("Subject: $subject\n\n");
$sender->datasend ("$body\n");
$sender->dataend();
$sender->quit();
}
close(LIST);
Hope this helps. Cheers,
ibanix
$ echo '$0 & $0 &' > foo; chmod a+x foo; foo;