gokou
02-04-2003, 05:33 PM
I am new to cgi-bin and I am trying to get a guestbook to work that is off of the htmlgoodies tutorials. I have a directory called cgi-bin and I have the guestbook script inside that directory called guestbook.cgi. I also have the html form page saved in the httpdocs directory. Now, when I fill out the form and hit send, I get an internal Error. What it's suppose to do is send to my email.
Heres the HTML code.
<HTML>
<HEAD>
<TITLE>Guestbook Script</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF">
<FORM METHOD="post" ACTION="/cgi-bin/guestbook.cgi">
<INPUT NAME="name" SIZE=50 TYPE="text"> <B>Your Name</B><BR>
<INPUT NAME="email" SIZE=50 TYPE="text"> <B>Your E-Mail Address</B><BR>
<INPUT TYPE="hidden" NAME="submitaddress" VALUE="brucelee@uogameresources.com">
<B>Write to me below:</B><P>
<TEXTAREA NAME="feedback" ROWS=10 COLS=50></TEXTAREA><P>
<CENTER>
<INPUT TYPE=submit VALUE="SEND">
<INPUT TYPE=reset VALUE="CLEAR">
</CENTER>
</FORM>
</BODY>
</HTML>
Heres the cgi-bin code
#!/usr/bin/perl
# That is the path to PERL just above It MUST be first in the script
# The following accepts the data from the form
if ($ENV{'REQUEST_METHOD'} eq 'POST') {
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$FORM{$name} = $value;
}
# The following sends the email
open (MESSAGE,"| /usr/lib/sendmail -t");
print MESSAGE "To: $FORM{submitaddress}\n";
print MESSAGE "From: $FORM{name}\n";
print MESSAGE "Reply-To: $FORM{email}\n";
print MESSAGE "Subject: Feedback from $FORM{name} at $ENV{'REMOTE_HOST'}\n\n";
print MESSAGE "The user wrote:\n\n";
print MESSAGE "$FORM{feedback}\n";
close (MESSAGE);
&thank_you;
}
#The following creates the Thank You page display
sub thank_you {
print "Content-type: text/html\n\n";
print "<HTML>\n";
print "<HEAD>\n";
print "<TITLE>Thank You!</TITLE>\n";
print "</HEAD>\n";
print "<BODY BGCOLOR=#FFFFCC TEXT=#000000>\n";
print "<H1>Thank You!</H1>\n";
print "\n";
print "<P>\n";
print "<H3>Your feedback is greatly appreciated.<BR>\n";
print "<P>\n";
print "</BODY>\n";
print "</HTML>\n";
exit(0);
}
Heres the HTML code.
<HTML>
<HEAD>
<TITLE>Guestbook Script</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF">
<FORM METHOD="post" ACTION="/cgi-bin/guestbook.cgi">
<INPUT NAME="name" SIZE=50 TYPE="text"> <B>Your Name</B><BR>
<INPUT NAME="email" SIZE=50 TYPE="text"> <B>Your E-Mail Address</B><BR>
<INPUT TYPE="hidden" NAME="submitaddress" VALUE="brucelee@uogameresources.com">
<B>Write to me below:</B><P>
<TEXTAREA NAME="feedback" ROWS=10 COLS=50></TEXTAREA><P>
<CENTER>
<INPUT TYPE=submit VALUE="SEND">
<INPUT TYPE=reset VALUE="CLEAR">
</CENTER>
</FORM>
</BODY>
</HTML>
Heres the cgi-bin code
#!/usr/bin/perl
# That is the path to PERL just above It MUST be first in the script
# The following accepts the data from the form
if ($ENV{'REQUEST_METHOD'} eq 'POST') {
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$FORM{$name} = $value;
}
# The following sends the email
open (MESSAGE,"| /usr/lib/sendmail -t");
print MESSAGE "To: $FORM{submitaddress}\n";
print MESSAGE "From: $FORM{name}\n";
print MESSAGE "Reply-To: $FORM{email}\n";
print MESSAGE "Subject: Feedback from $FORM{name} at $ENV{'REMOTE_HOST'}\n\n";
print MESSAGE "The user wrote:\n\n";
print MESSAGE "$FORM{feedback}\n";
close (MESSAGE);
&thank_you;
}
#The following creates the Thank You page display
sub thank_you {
print "Content-type: text/html\n\n";
print "<HTML>\n";
print "<HEAD>\n";
print "<TITLE>Thank You!</TITLE>\n";
print "</HEAD>\n";
print "<BODY BGCOLOR=#FFFFCC TEXT=#000000>\n";
print "<H1>Thank You!</H1>\n";
print "\n";
print "<P>\n";
print "<H3>Your feedback is greatly appreciated.<BR>\n";
print "<P>\n";
print "</BODY>\n";
print "</HTML>\n";
exit(0);
}