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;

In reply to Re: cant send a mass email by ibanix
in thread cant send a mass email by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.