PDA

View Full Version : Sendmail / CGI confusion - help needed please


stephenc
12-27-2002, 07:05 PM
I'm trying to configure formmail, but I think I'm on the wrong track.

The URL's of the files are -
http://www.sitedesigns4u.co.uk/formmail.html
http://www.sitedesigns4u.co.uk/cgi-bin/formmail.cgi

Am I correct in thinking that all I need to do is -

1 Edit formmail.html line
<FORM ACTION="http://www.sitedesigns4u.co.uk/cgi-bin/formmail.cgi" METHOD=POST> to the address where I upload the formmail.cgi script on my server.

2 Upload it in Ascii and chomod it to 755.

3 Edit formmail.cgi shebang line.

4 Edit formmail.cgi
open(MAIL, "|/usr/sbin/sendmail -t") || Error ('open', 'mail program');
to my host's path to sendmail.

5 Upload it in Ascii and chomod it to 755.

6 Run the formmail.html

Its just that the script will not run at all. Am I totally on the wrong line of thinking here?

Stephen
code is as follows for both -

Formmail.cgi -
#!/usr/bin/perl -wT
use strict;
use CGI ':standard';
my ($to, $from, $subject, $contents);

print "Content-type:text/html\n\n";

#$to = param('to');
$from = param('from');

$subject = param('subject');
$contents = param('contents');

open(MAIL, "|/usr/sbin/sendmail -t") || Error ('open', 'mail program');

print MAIL "To: stephen\@sitedesigns4u.co.uk \nFrom: $from\n";
print MAIL "Subject: $subject\n";
print MAIL "$contents\n";

close(MAIL);

print "Thanks for your comments and feedback.";

sub Error {
print "The server can't $_[0] the $_[1]: $! \n";
exit;
}

formmail.html -

<HTML>
<HEAD>

<TITLE>Send e-mail to Stephen</TITLE>


</HEAD>
<BODY>

<FORM ACTION="http://www.sitedesigns4u.co.uk/cgi-bin/formmail.cgi" METHOD=POST>
<b><font size=+1>Write an email:</font></b>
<table border=0>
<tr><td align=right>To: </td><td><INPUT TYPE="text" NAME="to"></td></tr>
<tr><td align=right>From: </td><td><INPUT TYPE="text" NAME="from"></td></tr>
<tr><td align=right>Subject: </td><td><INPUT TYPE="text" NAME="subject"></td></tr>

<tr><td align=right>Contents: </td><td><TEXTAREA NAME="contents" ROWS=4 COLS=40></TEXTAREA></td></tr>

<tr><td>&nbsp;</td><td><INPUT TYPE="submit" VALUE="Send e-mail"> <INPUT TYPE="reset" VALUE="Erase e-mail"></td></tr>
</table></FORM>
</BODY>
</HTML>

Grizz2
12-28-2002, 06:08 PM
Everything looks ok except this part.
1 Edit formmail.html line
<FORM ACTION="http://www.sitedesigns4u.co.uk/cgi-bin/formmail.cgi" METHOD=POST> to the address where I
upload the formmail.cgi script on my server.

2 Upload it in Ascii and chomod it to 755.

You don't chmod the form page to 755. That is for your cgi scripts. Just upload like you would any other html page. I've never tried setting an html page to 755, but thats the only thing I see offhand that "might" cause problems.
Are you getting a 500 server error when you submit the form?
Grizz

Philip M
12-28-2002, 06:22 PM
I don't think it would matter for this purpose if the html page is set to CHMOD 755 as it is normally 644 anyway.

Are you sure that the files are in the right directory, and the cgi-bin directory itself is set to CHMOD 755? And the script ditto.

You say the script does not run at all. Are you getting some sort of error message, and if so what is it, as that will probably hint at the source of the problem.

I have now tried the form, and received:-

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, admin and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.


This suggests a syntax error in the script, or incorrect CHMOD value.

stephenc
12-28-2002, 10:11 PM
Hi guys

Thanks for trying to help me - I've checked and verified the directories at -

http://www.sitedesigns4u.co.uk/formmail.html
and
http://www.sitedesigns4u.co.uk/cgi-bin/formmail.cgi

I've also checked the permissions again, though I cant see that the form chomod could be a problem, but I've reset it anyway.

I'd be glad to try anything else before I move onto scrapping this script and trying to install Matts script formmail, but I'm guessing that I might have the same problem.

I know that the cgi is enabled as I have a 'content management' script using cgi installed and its working fine. Anyone any ideas please?

Stephen:confused:

crackn101
12-29-2002, 07:24 AM
Hi.

My server will not run this script unless I take off the T from
the perl shebang.

#!/usr/bin/perl -wT to #!/usr/bin/perl -w

Once I did this, the script ran fine.

Take Care.

crackn101

stephenc
12-29-2002, 11:21 AM
:thumbsup: crackn101

You've cracked it - many thanks. I'm not sure why it didn't work with the T (to protect against 'T'ainted data as this code was taken straight from Elizabeth Castro's book Perl and CGI.

Now all I have to do is refine it to the point where it is secure, looks good and add more fields.

Thanks to all who advised and in particular :thumbsup: to crackn101

Stephen