Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

FormMail

Status
Not open for further replies.

secretsquirrel

Programmer
Mar 22, 2001
202
GB
hi all,

you've probably heard this problem a thousand times before, but i can't find the answer in this forum.

i've downloaded the FormMail cgi script from scriptarchive.com, read and followed the instructions that come with it, but am still unable to run the script.

i've pointed the script to perl and sendmail and, for testing purposes, i've put together an extremely simple page containing just a name field and an e.mail address field.

however, when the form is submitted, all i get is a '500 internal server error' page and a 'premature end of script header' entry in my error log.

let me know if you want a url to my page or a copy of the script.

thanks in advance for any help,

ss...
 
thanks tom, i've had a look through this faq (and the other one it mentions), but i still can't find what's wrong.

this faq talks about finding errors, but the only error i get (or at least the only one i can find) is the 'premature end of script headers' error.

i am a cgi newbie and don't want to mess about with the code too much for fear of breaking it beyond repair.

fyi, the url to my page is
thanks,

ss...
 
That FAQ covers how to find out what the error is. If you have not narrowed it down further, you have not followed all of the steps in the FAQ. There is no way for me or anyone else to know what the problem is unless you perform some basic debugging. Did you print out the http content header? Did you upload the file in ASCII mode? Et cetera. Sincerely,

Tom Anderson
Order amid Chaos, Inc.
 
thanks tom,

i've been through the faq again, but because i'm new to cgi, some of the advice goes above my head. going through the faq step by step, i've done the following...

- i've made sure the script is being transferred as ascii
- i've set the permissions to 755
- i've made sure the shebang line is correct
- i know i can run cgi from my server
- i've located the modules i need (presumably this means sendmail, etc.)

...and then it gets confusing...

- i have no idea what 'use strict' means, or what to do with it or where to put it
- where am i supposed to put 'print "Content-type: text/html\n\n"', and what is it supposed to do?
- i can get hold of my error log, and all it tells me is the error i mentioned in my earlier posts
- i've put the 'use CGI::Debug (report=>'everything',on=>'anything');' line in my script, but as far as i can see it makes no difference in either my browser or my error log

basically, i've done what i can with my limited cgi knowledge and i'm not getting any further

thanks,

ss...
 
1. 'use strict' should be put at the top of the code near where any modules are called. After the shebang, but before any code. What it does is prevent bad programming by producing errors on bad constructs, like using a variable before actually declaring it. This helps you by showing you code that may be producing your error.

2. You should 'print "Content-type: text/html\n\n"' before outputting anything else. It should be the very first print statement. It tells the web browser to expect content of type text/html. Unless you do that, the browser will not know how to interpret anything it receives. This is a part of the HTTP protocol.

3. If you've put the 'use CGI::Debug (report=>'everything',on=>'anything');' line in your script at the top after the shebang but before any other code, then it should output your errors to your web browser. Be certain that you have that module installed before trying to use it, or that will be the source of one of your errors.

4. Try writing a "hello world" program, to see if that runs. If it doesn't, then you're not doing one of the first basic steps (ASCII mode, chmod 755, etc.). If it does run, then try adding some code to it, like using the modules that your formmail script does. Sincerely,

Tom Anderson
Order amid Chaos, Inc.
 
thanks tom,

this is starting to make a lot more sense to me now!

at least i'm now getting a list of errors in the script, and most of them seem to suggest my reference to sendmail and other programs is incorrect, so i'll check it out.

thanks again,

ss...
 
Try copying and pasting this into a file and call it from the web browser. If this works, thenit is definitely something with the file you are using. If it does not work, then it is a misconfiguration in apache, or permission errors.


#!/usr/bin/perl

print "Content-type: text/html\n\n"
print &quot;<body bgcolor=\&quot;navy\&quot;><font size=\&quot;-2\&quot; color=\&quot;white\&quot;>\n&quot;;
print &quot;<center><h2>Hello World</h></center>\n&quot;;
print &quot;<br>&nbsp\n&quot;;
exit 0;
 
oops!

I left the semicolin from frist line:

First line reads:
print &quot;Content-type: text/html\n\n&quot;

Should be:
print &quot;Content-type: text/html\n\n&quot;;

Sorry
 
thanks guys,

i'm slowly getting further with this, but it still won't work.

this is probably a dumb question, but...

my error log now gives me the error 'Global symbol &quot;$mailprog&quot; requires explicit package name' at the line where i first try and call sendmail. does this simply mean that my path to sendmail is wrong? because i've already confirmed the path with my system administrator.

thanks in advance,

ss...
 
No, it means you haven't declared it. If you are using 'strict', then you have to declare variables with 'my'. Eg:

Code:
my $mailprog = &quot;/usr/bin/sendmail&quot;;
Sincerely,

Tom Anderson
Order amid Chaos, Inc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top