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

Greetings, monks, I am a perl novice, so forgive me my naivetee.

I have been attempting to get a "simple" form mail working from my server. I shebang, I upload ASCII, I chmod 755, but, alas, no matter what tutorial I seek or any variation I try, I end up with a server error: Premature end of script headers: mailer.pl

I am currently trying to use mailer.pl from James Marshall at http://www.jmarshall.com/easy/cgi/. My silly sample form is located at http://thrall.library.hope.edu/~dahm/sample_form.html

I do not understand the error, nor the entire script. I simply inserted my e-mail address into the appropriate place (elizabeth.dahm@hope.edu, if any one cares reply), did a whereis sendmail and thought what was all ready there was appropriate.

If you could offer me any guidance, it would be greatly appreciated.

  • Comment on consistent form mail error: premature end of script headers

Replies are listed 'Best First'.
Re: consistent form mail error: premature end of script headers
by chromatic (Archbishop) on Jan 17, 2003 at 20:50 UTC

    Would you be willing to use a different mailer? The nms projects has a well-written and secure form mail program with documentation and user support. Looking at Mr. Marshall's program, it's not the sort of thing I'd want on my server. (It's written in Perl 4, which has been obsolete for nearly a decade.)

    The error message you received indicates that the program died (or gave an error message) before it could send anything back to the web browser. It's not immediately obvious why this is, but fixing the issues with the code would take longer than recommending a better starting point.

      Just a quick question, which is kind of related:-

      Are there any other script providers of a similar quality to those of the nms project? I find it very difficult to find decent scripts to use as learning aids, or that I can recommend to others.

      (I'm hoping this isn't too off-topic as the original poster would probably also appreciate knowing about similar sites.)

      Thank you for replying. I am certainly open to any mail script, and I tried the one you suggested. Though I have not worked through it intensively, my intial test (http://thrall.library.hope.edu/~dahm/sample_form.html) provided the same script header error.

      I also attempted a simple form that would only post the data to another website, and that failed as well. Strangely, my "hello, world" program works find.

      Does the fault lie with the server? We're running a recent version of RedHat Linux with an Apache webserver. Is there any kind of settings that I should make sure are correct?

Re: consistent form mail error: premature end of script headers
by HamNRye (Monk) on Jan 17, 2003 at 21:41 UTC

    I have checked the script and it appears OK. However, it does not appear to be a decade out of date. Written in 1997 by James Marshall, james@jmarshall.com

    The 500 server error is common for newbies... Are you sure you FTP'ed it correctly??

    The script won't run? Check the "here-documents", which look something like this:

    # Similar code appears on line 59 of mailer.pl print << "END"; Hello World! END

    The quoted token ("END" in this example, or whatever is used in your script) must EXACTLY match the token that terminates the text. It may look OK to you, but if you've moved the file from DOS/Windows to UNIX, remember that UNIX uses <LF> to delimit lines and DOS/Windows uses <CR><LF>. What that means to Perl is that there is an invisible <CR> in the end token, but there isn't one in the quoted token. Guess what? They don't match, at least in Perl's opinion. Make sure that the end token is flush on the left margin with a <LF> following it - and no trailing space or hidden <CR> on the line.

    The easiest way to do this is to simply hit the Return key right after the end token, whether it needs it or not. That way you'll know its the right line delimiter for your system. <Checking the script on your system, the script cannot even report that it recieved no arguments (first part of the routine.) My guess is that you have uploaded the script improperly.

    Another tool in the debugging arsenal is to use CGI::Carp. Its now part of the standard Perl distribution, but if you have an earlier version you can download it from CPAN.

    Somewhere near the top of your script type use CGI::Carp qw(fatalsToBrowser);

    This will redirect all fatal error messages to your browser, so you have a better idea of what is going wrong.

    If nothing else, adding the Carp line to your program will help the monks better determine what is not happening.

    ~Hammy