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.


In reply to Re: I'm getting a 500 Internal Server Error - how can I make this work? by graff
in thread I'm getting a 500 Internal Server Error - how can I make this work? by linex

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.