E-mail script using address book

I'm trying to read the e-mail addresses from a text file as if it were an address book. My e-mail script worked fine before, but since I've tried to add this feature, it won't work. Can any one help?
---------------------------------------
text file:

name@name.com
address@address.com
---------------------------------------
perl script:

#!/usr/bin/perl

    %Config = ('to','','subject','','from','','realname','','content','');


    if ($ENV{'REQUEST_METHOD'} eq 'GET') {
        @pairs = split(/&/, $ENV{'QUERY_STRING'});
    }
    elsif ($ENV{'REQUEST_METHOD'} eq 'POST') {
        read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
 
        @pairs = split(/&/, $buffer);
    }
    else {
        &error('request_method');
    }

    foreach $pair (@pairs) {

        local($name, $value) = split(/=/, $pair);
 
        $name =~ tr/+/ /;
        $name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;

        $value =~ tr/+/ /;
        $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;

        $value =~ s/<!--(.|\n)*-->//g;

        if (defined($Config{$name})) {
            $Config{$name} = $value;
        }
        else {
            if ($Form{$name} && $value) {
                $Form{$name} = "$Form{$name}, $value";
            }
            elsif ($value) {
                push(@Field_Order,$name);
                $Form{$name} = $value;
            }
        }
    }

    $Config{'required'} =~ s/(\s+|\n)?,(\s+|\n)?/,/g;
    $Config{'required'} =~ s/(\s+)?\n+(\s+)?//g;
    $Config{'env_report'} =~ s/(\s+|\n)?,(\s+|\n)?/,/g;
    $Config{'env_report'} =~ s/(\s+)?\n+(\s+)?//g;
    $Config{'print_config'} =~ s/(\s+|\n)?,(\s+|\n)?/,/g;
    $Config{'print_config'} =~ s/(\s+)?\n+(\s+)?//g;

    @Required = split(/,/,$Config{'required'});
    @Env_Report = split(/,/,$Config{'env_report'});
    @Print_Config = split(/,/,$Config{'print_config'});


$mailprog = '/usr/sbin/sendmail';


# Send E-Mail
   
    open(MAIL, "|$mailprog -t");
    open(NOTIFY, "<notify.txt");

    @list = <NOTIFY>;
    foreach $item (@list){
    print MAIL "To: $item\n";
    print MAIL "From: name\@somewhere.com\n";

    if ($Config{'subject'}) { print MAIL "Subject: $Config{'subject'}\n\n" }
    else                    { print MAIL "Subject: No Subject\n\n" }

    print MAIL "$Config{'content'}\n";

    close (MAIL);
    close (NOTIFY);

print "Content-type:text/html\n\n";
print "All messages sent.";
kch011099Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

thoellriCommented:
Have you tried rearranging the mail sending part?

                           # Send E-Mail
                           
                           open(NOTIFY, "<notify.txt");
                           @list = <NOTIFY>;
                           close(NOTIFY);
                           foreach $item (@list){
                             open(MAIL, "|$mailprog -t");
                             print MAIL "To: $item\n";
                             print MAIL "From: name\@somewhere.com\n";

                             if ($Config{'subject'}) {
                               print MAIL "Subject: $Config{'subject'}\n\n"
                             } else {
                               print MAIL "Subject: No Subject\n\n";
                             }
                             print MAIL "$Config{'content'}\n";
                             close (MAIL);
                           }
                           print "Content-type:text/html\n\n";
                           print "All messages sent.";


Hope this helps
  Tobias
0
maneshrCommented:
i think you need to escape the individual $item's before you  send them (the way you use name\@somewhere.com)

so insert this line right after

foreach $item (@list){
  $item=~ s/@/\\\@/;
.....
0
thoellriCommented:
Why would you need to escape them? I don't see an eval anywhere?

0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

kch011099Author Commented:
For some reason, it's not reading the notify file. Anyone got any ideas?
0
kch011099Author Commented:
I added a print "$item"; command in the foreach loop, but it didn't print anything.
0
maneshrCommented:
check the permission for the notify.txt file

heres the code i used to test...

#!/usr/local/bin/perl

open(IN,"./mail.txt") || die $!;
@mails=<IN>;
close(IN);

foreach $to (@mails){
  $to=~ s/@/\\\@/;
  print $to,"\n";
}

==========mail.txt==========
mehere@hotmail.com
jitu7125@yahoo.com

===========
0
thoellriCommented:
what does:

 open(NOTIFY, "<notify.txt") || die "Can't open address book - $!";

in the above script give you?

Tobias
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
kch011099Author Commented:
I fixed my problem. I just moved the txt file out of the cgi-bin and into a new folder. Now it works, thanks for your help. I will still give out the points.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Perl

From novice to tech pro — start learning today.