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!

Help with a simple form!

Status
Not open for further replies.

zavsays

Technical User
Apr 19, 2001
117
US
Hi all,

I'm very new to cgi and I've been struggling for days trying to make a form work for me. This one is the closest I've come that is to say ... at least it spits back a reply in the browser saying "Your Request Has Been Submitted". Problem is, it doesn't email me the information (I don't know where it goes). Here's the code from the funform.cgi ....(Yes, it resides in the cgi folder). I must be missing some information. There seem to be more instructions before the program starts ... (#let SEND_MAIL="Y ?) but I don't understand them.

Thanks!

#!/usr/bin/perl
# A general purpose form decoder for use with all forms.
#
# what it does is accept any information from ANY HTML form
# formats it, and mails it.
#
# To operate properly, the form must have the following
# entries:
# <INPUT TYPE="hidden" NAME="FORM_NAME" VALUE="Friendsofphilly">
# <INPUT TYPE="hidden" NAME="MAIL_TO" VALUE="zavsays@comcast.net">
# This way the person receiving the mail knows where it came from
# The MAIL_TO is the person you want to receive the submission
#
# 1997 by bruce gronich for the public domain.
#This program is intended to be used as a learning tool. It
#is given freely AS IS and comes with no warranty. The author
#is not responsible for any damages caused by its use or
#misuse.

#cp the funform.html to your html root directory.
#modify the funform.html to meet your needs.
#change the name of the path of the /cgi-bin/ if needed

#BNB SAYS- Configure this to your sendmail
$mail_program="/usr/lib/sendmail -t ";

#BNB SAYS- Set these options to meet your needs

#let SEND_MAIL="Y" when you are done testing and want mail to be sent
$SEND_MAIL="N";

######################################################################
###### THIS IS WHERE OUR PROGRAM STARTS! #############################
######################################################################

#This first part of the program splits up our data and gets it
#ready for formatting and mailing.
$i=0;
read(STDIN,$temp,$ENV{'CONTENT_LENGTH'});
@pairs=split(/&/,$temp);
foreach $item(@pairs)
{
($key,$content)=split(/=/,$item,2);
$content=~tr/+/ /;
$content=~s/%(..)/pack("c",hex($1))/ge;
$fields{$key}=$content;
$i++;
$item{$i}=$key;
$response{$i}=$content;
}

#Re-assign a couple of variables for readability reasons
$send_to = $fields{MAIL_TO};
$form_id = $fields{FORM_NAME};
$msg_from = $fields{E_MAIL};


#Set up our HTML Result Form
print "Content-type: text/html\n\n";
print "<HTML>\n";
print "<HEAD>\n";
print "<TITLE>Information submission result</TITLE>\n";
print "</HEAD>\n";
print "<BODY BGCOLOR=#FFFFFF LINK=#4133EF ALINK=FF0000 VLINK=#FF0000>\n";
print "<CENTER>\n";

if ($SEND_MAIL eq "Y")
{
open (MAIL, "|$mail_program") ||
die "Unable to run mail program\n";
print MAIL <<__STOP_OF_HEADER__;
To: $send_to
From: $msg_from
Subject: $form_id RESPONSE

__STOP_OF_HEADER__
}

print "<H1>Your Request has been Submitted!</H1>\n";
print "<A HREF=$ENV{'HTTP_REFERER'}>\n";
print "<B>CLICK HERE!</B></A> To return to the previous page<P>\n";
print "</CENTER>\n";
print "<B>Here is the information you sent:</B><P>\n";
print "<PRE>";
print "<HR>\n";
print " SUBMISSION FORM: $form_id\n";
print " E-MAIL TARGET: $send_to\n";
print "<HR>\n";

$i=1;
while ( $item{$i} gt " ")
{
if ($SEND_MAIL eq "Y")
{
print MAIL " $item{$i}: $response{$i}\n";
}
print " $item{$i}: $response{$i}\n";
$i++;
}
print "</PRE>";
print "<HR>\n";
print "</BODY>\n";
print "</HTML>\n";

#CLOSE THE MAIL PROGRAM IF WE ARE MAILING
if ($SEND_MAIL eq "Y")
{
close (MAIL);
}

######################################################################
###### THIS IS WHERE OUR PROGRAM ENDS! ###############################
######################################################################
 
Just an observation.
Your code is quoted as HTML.
Code:
if ($SEND_MAIL eq "Y")
{
open (MAIL, "|$mail_program") ||
die "Unable to run mail program\n";
print MAIL <<__STOP_OF_HEADER__;
To: $send_to
From: $msg_from
Subject: $form_id RESPONSE

__STOP_OF_HEADER__
}
It may well work this way but I have always used it in the following way.
Code:
sub contact_mail{

	open( EZMAIL, "|/bin/easymail -t" ) or return 1; 
	print EZMAIL "From: $FROM\n";
	print EZMAIL "To: $TO\n"; 
	print EZMAIL "Subject: $SUBJECT\n"; 
	print EZMAIL "\n===================================\n";
	print EZMAIL "\n      $DATELINE - $TIMELINE\n";
	print EZMAIL "\n===================================\n";
	print EZMAIL "\n";
	print EZMAIL "$NOTEY\n"; 
	print EZMAIL "Surname - $SNAME\n"; 
	print EZMAIL "Email - $EMAIL\n";
	print EZMAIL "\n";
	print EZMAIL "Enquiry:-\n";
	print EZMAIL "==============\n";
	print EZMAIL "$MESSAGE\n";
	print EZMAIL "==============\n";
	close( EZMAIL );

}

Keith
 
OK - three things to change/try, from the top...
Code:
# To operate properly, the form must have the following entries: (...)
# <INPUT TYPE="hidden" NAME="MAIL_TO" VALUE="zavsays@comcast.net">
This is an old script, and an old (and discredited) method of passing the "to" address. There's no reason to leave your address sitting on the page where spammers can see it (and maybe abuse your script) - remove that <input> from your page and change this line:
Code:
$send_to = $fields{MAIL_TO};
to this:
Code:
$send_to = 'zavsays@comcast.net';

Next, there's a line that tells the script where the sendmail program is:
Code:
$mail_program="/usr/lib/sendmail -t ";
You need to check with your ISP that this is where sendmail lives. If you're not being hosted on Unix, you might have to use something else entirely...


Finally there's a flag at the top that controls whether or not mail is sent:
Code:
$SEND_MAIL="N";
You need to change that value to "Y" if you want to get any mail.

-- Chris Hunt
Webmaster & Tragedian
Extra Connections Ltd
 
Thanks guys! I'll give those suggestions a try!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top