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

I've been playing with a script that jeffa wrote, CGI mailto via code reuse (AKA the CPAN). And I can't seem to get it to work. The script is identical to what jeffa wrote, with the exception of changing the email addresses. But running this through Apache 1.3.28 I keep getting "premature end of headers" in my error.log.

I've tried adding a $|++; with no change in results. When I run this from the command line I'm getting HTML output. Suggestions more than welcome.

The output of the script from the command line:
Content-Type: text/html; charset=ISO-8859-1 <?xml version="1.0" encoding="iso-8859-1"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en-US" xml:lang="en-U +S"><head><title>The Form</title> </head><body> <form method="post" action="/mail_it.cgi" enctype="application/x-www-f +orm-urlencoded"> name: <input type="text" name="name" /><br /> email: <input type="text" name="email" /><br /> address1: <input type="text" name="address1" /><br /> address2: <input type="text" name="address2" /><br /> city: <input type="text" name="city" /><br /> state: <input type="text" name="state" /><br /> zip: <input type="text" name="zip" /><br /> homephone: <input type="text" name="homephone" /><br /> workphone: <input type="text" name="workphone" /><br /> business: <input type="text" name="business" /><br /> goals: <input type="text" name="goals" /><br /> comments: <input type="text" name="comments" /><br /> <input type="submit" name="mail_it" value="mail_it" /><div></div></for +m></body></html>

Everything appears to be working correctly. But either Apache doesn't like this, or the CGI header isn't working like I'd expect.

While I think this is probably an Apache problem, I'm not clear enough on my CGI to be able to point definitively to it. Note that I have successfully created other CGI scripts without this problem. So it seems that CGI is horking on complicated scripts but working fine for straightforward scripts.

What am I overlooking? Which M should I be RTFing?

Replies are listed 'Best First'.
Re: CGI Header problem/question
by OverlordQ (Hermit) on Dec 20, 2003 at 17:41 UTC
    Had this exact same problem myself the otherday, was an exact copy of working code, and it ended up being #1 in my list of things to check.

    1) Check permissions, of the file AND the folder (read: check suexec.log too)
    2) Doublecheck you can exec cgi's in that folder
    3) Triplecheck the shebang.

      OK, file this whole thing under "Oh My Dog I'm missing the obvious".

      Shebang? What shebang? I was running the script from the command line via perl mail_it.cgi.

      And of course once I add a shebang it works fine. Doh! Thanks.

Re: CGI Header problem/question
by b10m (Vicar) on Dec 20, 2003 at 17:47 UTC
    I keep getting "premature end of headers" in my error.log

    I highly doubt that this is all you get, looking in your error log file. It probably contains more information, that could help you spot the error. What I always do, is:

    $ tail -f /path/to/error.log
    and press enter a couple of times, so it's clear where new input starts. Then re-run the script. All the appropriate errors will be shown.

    You provide too little information, for -at least- me to figure out what is wrong. Please paste the exact error that you get (there's got to be more than the premature end of headers) and the appropriate code that you use.

    Update: Once again ... I type to slow, since the "right answer" seems to be given and confirmed already...

    --
    b10m
      Although the answer was already given, I just wanted to mention that the error really isn't much more than what I stated. The full error from the error_log:
      [Sat Dec 20 10:29:44 2003] [error] (8)Exec format error: exec of /Libr +ary/WebServer/CGI-Executables/mail_it.cgi failed [Sat Dec 20 10:29:44 2003] [error] [client 192.168.1.1] Premature end +of script headers: /Library/WebServer/CGI-Executables/mail_i t.cgi

      Not a lot to go on. As far as the code used, that's in the link at the top of the post. :)

        The first line of the error_log that you didn't include in your original post is actually the useful one that would have given the clue as to what the problem was. The "premature end of script headers" just means that the error happened and the script aborted (or in your case never executed) before the headers could be sent. It pretty much always follows the real error message and is therefore not of any help in diagnosing a script error.
Re: CGI Header problem/question
by oha (Friar) on Dec 20, 2003 at 18:51 UTC
    sorry if i can't help, but the same thing happened to me with Kwiki 0.18. Kwiki 0.17 is ok.

    i considered permissions, and other... no way to find out the reason.

    i executed these she-bang scripts and compared the headers, and they looks the same.

    i tryied to see the output for special-chars but i discovered nothing.

    maybe a flush in headers confuse apache?