Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Newbie form-mail.pl question

Reply
Thread Tools

Newbie form-mail.pl question

 
 
Jo
Guest
Posts: n/a
 
      12-12-2003
Hello

I have no perl experience at all but I have what seems to be a fairly
straightforward task to perform.

My client's site has a contact form that is controlled by
form-mail.pl. I would like the form to go to a file called
thankyou.htm that is stored at the root level of the site.

Below is a copy of the script and it would appear that is generates a
simple thank you page itself. Could anyone tell me in idiot-terms
what I need to do to make the script direct visitors to the right
page?

Thanks very much in advance - and sorry for taking up your time with
such a simple question.

Jo




#!/bin/perl



# ------------------------------------------------------------

# Form-mail.pl, by Reuven M. Lerner ((E-Mail Removed)).

#

# Last updated: March 14, 1994

#

# Form-mail provides a mechanism by which users of a World-

# Wide Web browser may submit comments to the webmasters

# (or anyone else) at a site. It should be compatible with

# any CGI-compatible HTTP server.

#

# Please read the README file that came with this distribution

# for further details.

# ------------------------------------------------------------



# ------------------------------------------------------------

# This package is Copyright 1994 by The Tech.



# Form-mail is free software; you can redistribute it and/or modify it

# under the terms of the GNU General Public License as published by
the

# Free Software Foundation; either version 2, or (at your option) any

# later version.



# Form-mail is distributed in the hope that it will be useful, but

# WITHOUT ANY WARRANTY; without even the implied warranty of

# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU

# General Public License for more details.



# You should have received a copy of the GNU General Public License

# along with Form-mail; see the file COPYING. If not, write to the
Free

# Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.

# ------------------------------------------------------------



# Define fairly-constants



# This should be set to the username or alias that runs your

# WWW server.

$recipient = '(E-Mail Removed)';



# This should be set to the URL of your home page, or wherever

# you wish users to return.

$homepage = 'http://www.XXX.co.uk/';



# This should match the mail program on your system.

$mailprog = '/usr/lib/sendmail';



# Print out a content-type for HTTP/1.0 compatibility

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



# Print a title and initial heading

print "<Head><Title>Thank you</Title></Head>";

print "<Body><H1>Thank you</H1>";



# Get the input

read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});



# Split the name-value pairs

@pairs = split(/&/, $buffer);



foreach $pair (@pairs)

{

($name, $value) = split(/=/, $pair);



# Un-Webify plus signs and %-encoding

$value =~ tr/+/ /;

$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;



# Stop people from using subshells to execute commands

# Not a big deal when using sendmail, but very important

# when using UCB mail (aka mailx).

# $value =~ s/~!/ ~!/g;



# Uncomment for debugging purposes

# print "Setting $name to $value<P>";



$FORM{$name} = $value;

}



# If the comments are blank, then give a "blank form" response

# &blank_response unless $FORM{'comments'};



# Now send mail to $recipient



open (MAIL, "|$mailprog $recipient") || die "Can't open $mailprog!\n";

print MAIL "Reply-to: $FORM{'username'} ($FORM{'realname'})\n";

print MAIL "Subject: WWW comments (Forms submission)\n\n";

print MAIL "$FORM{'username'} ($FORM{'realname'}) sent the
following\n";

print MAIL "Company Name = $FORM{'CompanyName'}\n";

print MAIL "Name of Booker = $FORM{'NameofBooker'}\n";

print MAIL "Address1 = $FORM{'Address1'}\n";

print MAIL "Address2 = $FORM{'Address2'}\n";

print MAIL "Address3 = $FORM{'Address3'}\n";

print MAIL "Address4 = $FORM{'Address4'}\n";

print MAIL "Postal code = $FORM{'Postcode'}\n";

print MAIL "Telephone = $FORM{'Telephone'}\n";

print MAIL "Fax = $FORM{'Fax'}\n";

print MAIL "Email = $FORM{'Email'}\n";

print MAIL "Comments = $FORM{'Comments'}\n";

print MAIL "Course name = $FORM{'CourseName'}\n";

print MAIL "Dates = $FORM{'Dates'}\n";

print MAIL "Cost = $FORM{'Cost'}\n";

print MAIL "Delegate names = $FORM{'DelegateNames'}\n";

print MAIL "Total places = $FORM{'TotalPlaces'}\n";

print MAIL "Total Cost ExVat = $FORM{'TotalCostExVAT'}\n";

print MAIL "VAT = $FORM{'VAT'}\n";

print MAIL "Total = $FORM{'Total'}\n";

print MAIL "Purchase order ref = $FORM{'PO'}\n";

print MAIL "------------------------------------------------------------\n";

print MAIL "$FORM{'comments'}";

print MAIL "\n------------------------------------------------------------\n";

print MAIL "Server protocol: $ENV{'SERVER_PROTOCOL'}\n";

print MAIL "Remote host: $ENV{'REMOTE_HOST'}\n";

print MAIL "Remote IP address: $ENV{'REMOTE_ADDR'}\n";

close (MAIL);



# Make the person feel good for writing to us

print "Thank you for sending your booking information.";



# ------------------------------------------------------------

# subroutine blank_response

sub blank_response

{

print "Your comments appear to be blank, and thus were not sent ";

print "to our webmasters. Please re-enter your comments, or ";

print "return to our <A HREF=\"$homepage\">home page</A>, if you
want.<P>";

exit;

}
 
Reply With Quote
 
 
 
 
Gunnar Hjalmarsson
Guest
Posts: n/a
 
      12-12-2003
Jo wrote:
> Could anyone tell me in idiot-terms what I need to do to make the
> script direct visitors to the right page?


You would need to edit the script. But don't bother.

> # Form-mail.pl, by Reuven M. Lerner ((E-Mail Removed)).
> #
> # Last updated: March 14, 1994

----------------------------^^^^
!!!

Please ask your client to use a more recent and less insecure script.
This URL may be useful: http://nms-cgi.sourceforge.net/scripts.shtml

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

 
Reply With Quote
 
 
 
 
Neil Trigger
Guest
Posts: n/a
 
      12-13-2003
Funny, I just wrote an email to a friend of mine for the EXACT same reason.

I admit that the script you're using isn't great or anything, but the same
principles should (I hope) apply.

I wrote to him:
Now all you need to do is look for the "Print" command. The print command is
basicaly the output of the script (in this instance anyway).

there are two forms or the print command.

Print - which prints or outputs the information to the website. (You'll need
to alter this if you simply want the page to say "Thank you for your ****,
it's been sent to a boring bastard in an office somewhere".

and:

Print MAIL which is exactly what it says. it prints (or outputs) the
information to the mail that you have set up via the variables.

Variables are things that vary, like email address to send the email to, the
imput (which you change via the form on the first HTML page - written in
HTML).

A few syntax bits:

When you want the website to read:
I'd like to say "Thank you"

you need the script to say:
I'\d like to say \"Thank you\"

This is because the ' and " are both used as markers in the script, or parts
that the script would use to execute certain functions, rather than just
write it on the website you've been sent to. Therefore you need to put a \
so that the script ignores it and writes it like a regular character.

Likewise when the name of a field is put in, you must use this syntax
$Form{'First_Name'}

You'll only use this in the print Mail function i'd imagine because from
what i can gather you'll just need to create the thank you page in
dreamweaver and copy the script across into the CGI (Perl) document.

When you use the Print function in either print mail or print for HTML code,
you must ensure that the \ sign is still used. This is again done even when
scripting HTML within a perl script. Understand?

$Form{'First_Name'} shows the script that you're asking for the Field named
First_Name from the Form. I have loads of these that I use in writing
letters to Santa Clause.

Yeah, you can write a free message to Santa!
The site is at http://www.magic2k.com/seasonal/santaletter/
or visit http://www.magic2k.com and click on "seasonal" on the left hand
menu bar.

If you find the Print function in your own formmail.cgi , just adjust it and
play around. I swear to you, you'll get it pretty quickly, if you understand
the basics of HTML, Javascript and Perl come very easily.

Well I hope you've read thus far.

In short:
Print on its own (Not print mail) should read similar to (though not
exactly) this:

print "<table width=400px cellpadding=0 bgcolor=#000033><tbody><tr
bgcolor='#660000'><td colspan=2> <div align=center><p><strong><font
color=#FFFF00 size=4 face=Arial, Helvetica, sans-serif>I\'m Lee Francis.
Thanks For Popping In.</td></tr></table>";

Again note the \ before the '

The print mail you can either leave as it is or be a smart arse (like me)
and make it a little bit more user friendly.

Trust me. Look and ye shall find (oh and if you don't understand the little
squares when you open the .cgi file in notepad, it's because they're
carriage returns. you'll need to replace all squares with the enter or
return button. The quickest way to do that is to open the .cgi file in word,
save it (not save as, just save) as ASCCI in exactly the same format it was
before without any special formatting. you can then open it in notepad and
it's layed out for you in an easy to mannage pattern

All the bits of code beginning with the # symbol were written by Matt Wright
(The programmer) to make life easy for you when you customise it - so he
wants you to play with it.

Read and enjoy.

I'm going to learn Database integration at UNI next so wish me luck!

Good night.

--
Trigger ?
http://www.magic2k.com/
http://www.oddmap.co.uk


 
Reply With Quote
 
Jo
Guest
Posts: n/a
 
      12-15-2003
Thanks Guys

I really appreciate the time you have taken out to help me with my problem

Jo
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
VONAGE Newbie w/newbie question New_kid@nowhere.new VOIP 0 08-11-2007 01:40 PM
another newbie question from another newbie.... Lee UK VOIP 4 05-17-2005 04:10 PM
newbie: cisco vlan newbie question No Spam Cisco 3 06-07-2004 10:02 AM
dumb newbie question (or newbie dumb question) Jerry C. Perl Misc 8 11-23-2003 04:11 AM
Newbie! I'm a newbie! What's wrong with this program? Id0x Python 4 07-20-2003 11:40 PM



Advertisments