Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I put a subroutine to give me back a message on my CGI web form if sendmail is down to eliminate getting a 500 server error message. What syntax would I use to call the subroutine??
sub mal { print "Content-type: text/html\n\n"; print "<html><head><title>Sendmail problem</title></head>\n"; print "<body bgcolor=\"white\">\n"; print "<center><strong><h2><font color=red>Mail is down</font></h2 ></strong></center>\n"; print "</body></html>\n"; exit; }
Now here is where I am trying to put it in my open pipe area and here are some of my many attempts that are not working.
I still get the 500 web server error:
open (MAIL,"|$sendmail") || warn "&mal";
open (MAIL,"|$sendmail") || die &mal;
open (MAIL,"|$sendmail") || &mal;

Replies are listed 'Best First'.
Re: Web page output for sendmail problem
by iburrell (Chaplain) on Nov 21, 2002 at 17:54 UTC
    What is output to stderr for each case? The third possibility should work. Using warn or die is incorrect since they take a string to output to STDERR, not a function reference. You probably do want to put a warn inside mal() so the error is logged. Also, you should use or instead of || and mal() instead of &mal.
      Tried this and still no luck:
      open (MAIL,"|$sendmail") or mal();
Re: Web page output for sendmail problem
by arrow (Friar) on Nov 21, 2002 at 20:44 UTC
    Did you declare your subroutine in the same scope {i.e. the same file) or did you want to reference it through a subroutine file (i.e. require or use "subroutines.txt";? Also, use CGI::Carp, (use CGI::Carp qw(fatalsToBrowser);) and strict. It will save you at least one headached, guaranteed!
      Thanks for the answer, now it works! What the heck does this use CGI::Carp, (use CGI::Carp qw(fatalsToBrowser);) do?
Re: Web page output for sendmail problem
by arrow (Friar) on Nov 22, 2002 at 21:31 UTC
    The line use CGI::Carp qw(fatalsToBrowser);, which should be added at the top of your script, just below the #!/usr/local/bin/perl line and the print "Content-type: text/html\n\n"; line.
    Example:

    #!/usr/local/bin/perl


    print "Content-type: text/html\n\n";
    use CGI::Carp qw(fatalsToBrowser);


    This module will print out any fatal errors in your script to the browser, instead of the hated "500 error". Usually the information it prints is very helpful in debugging your script.

    Cheers