in reply to I'm getting a 500 Internal Server Error - how can I make this work?
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:
That deletes the file. Once it is deleted, the script might not have permission to create it again (the "web user" account running the script would need write access on that directory, which might be a bad idea, or at least, might not be allowed).if (($ENV{QUERY_STRING} eq "new") && (-e $file)){unlink($file);}
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).#!/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";
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.
|
|---|