in reply to I'm getting a 500 Internal Server Error - how can I make this work?

If you are certain that the error logs you reported in one of your other replies above actually came from your script (rather than someone else's), then you must have made some changes that you haven't posted.

The posted code does not contain any logic to print a message like "failed to open log file"; if you now have a modified version of your script that includes this sort of message, that is what's causing that error message.

As for the logic that is posted, there are problems:

If I can guess correctly about what you are trying to do here, it might make more sense like this (though I have no way to know whether this will actually work for you):
#!/usr/bin/perl -w use strict; my $mailprog = '/usr/lib/sendmail'; my $mail = 'recipient-email@adress.com'; my $from = 'sender-email@address.com'; my $file = 'report.txt'; my $num; if ($ENV{QUERY_STRING} ne "new" and -f $file) { open (DATA, $file); $num = <DATA>; close (DATA); $num =~ s/\D+//g; } $num ||= 0; if ( open (MAIL, "|$mailprog -t")) { print MAIL "Content-Type: text/plain; charset = windows - 1251\n"; print MAIL "Subject: Text, Text!\n"; print MAIL "To: $mail\n"; print MAIL "From: $from\n\n"; print MAIL "Hello, the message text itself..\n"; print MAIL "\n\n"; close (MAIL); $num++; } else { $num = "Unable to use $mailprog"; } if ( open (DATA, ">$file")) { print DATA $num; close (DATA); } else { my $might = ( -e $file ) ? 'does' : 'does not'; $num .= "<br>Unable to write to $file (it $might exist)."; } print "Content-type: text/html\n\n"; print "$num\n";
That ignores most of the other advice about using CGI and FatalsToBrowser, etc, but if you have the right path for sendmail, it should work, and if you don't, it will tell you about that (sendmail is /usr/sbin/sendmail on the unix systems that I am familiar with).

Meanwhile, if there's a problem with opening the "report.txt" file for output, it will tell you about that, too; if you want it to report about not being able to open this file for input, you should be able to figure that out. If your ultimate goal is to send a set of emails to different people (or the same message to the same person a bunch of times), just add the appropriate loop around that middle "if/else" block.