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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Very basic CGI Formmail

Status
Not open for further replies.

diggle

Instructor
Apr 4, 2004
1
0
0
GB
Hello
I am a novice. Need to know;
How to add a counter CGI script in an HTML file
How to add formmail script in my form. I have already made a form in Dreamweaver.

Thanks. Diggle
 
firstly...

make sure your HTML file contains the following form action and any fields you are interested in sit between the opening <form> and closing </form> tags


[blue]<FORM ACTION=" METHOD="GET">

<input type="text" name="???">
<input type="text" name="???">
<input type="text" name="???">
<input type="hidden" name="hiddenfield" value="?????">

</form>[/blue]

secondly...

upload the following script to your cgi-bin - saved as 'duncmail.pl' and set the permissions to be able to execute

change the red bit to your email address - DO NOT REMOVE THE BACKSLASH BEFORE THE @ SIGN


#!/usr/bin/perl

print "Content-type: text/html\n\n";
print "<HTML>\n<HEAD>\n<TITLE>Duncan Carr - Form Parser</TITLE>";
print "\n</HEAD>\n<BODY>";

$ENV{'QUERY_STRING'} =~ s/&Submit=Submit//;
$ENV{'QUERY_STRING'} =~ tr/+/ /;
$ENV{'QUERY_STRING'} =~ s/%(..)/pack("c", hex($1))/eg;

print "<h1>Duncan Carr - Form Parser</h1>\n\n";

@pairs = split (/&/, $ENV{'QUERY_STRING'});

foreach $pair (@pairs) {
($field, $value) = split (/=/, $pair);
$formdata{$field} = $value;
print "<li>$formdata{$field} => $value\n";
}

open (MAIL, '| /usr/sbin/sendmail -t');

print MAIL "From: Duncan Carr -> form parser\n";
print MAIL "To: [red]you\@whateverisp.com[/red]\n";
print MAIL "Cc:\n";
print MAIL "Bcc:\n";
print MAIL "Subject: form submission\n";

# body...

foreach $pair (@pairs) {
($field, $value) = split (/=/, $pair);
print MAIL "$field => $value\n\n";
}

close MAIL;

kind regards
Duncan
 
Diggle,

There are a number of free web counters available, but you're far better off to analyse your own weblogs for a more accurate picture - google will turn up quite a few of these


Formmail script, there's quite a few of these available as well, however, make sure the one you use does not have recipient as a hidden field in the form - this can set your server up as a spam relay

What webserver are you running, and what operating system?

--Paul



 
if you get this sorted (and I haven't @£$%^&! it up!) it should send you an email of the fields and their values :)


Kind Regards
Duncan
 
this is a sample email i have just received while answering this post:-

QID => 814797

Userid => 557043

postPID => 452

Page => 1

Handle => duncdude

Pass => xxxxxxxx

Topic => Very basic CGI Formmail

post => answer here...

ProcessEmot => 1

ProcessTGML => 1

frmShowSig => 1

SubReply => Submit Post


Kind Regards
Duncan
 
This is for unix? what can I do to make this work for Windows? I have active perl installed already!!
 
Hello Dunc,
I am a novice. And I need to do an Order Form. I use your code, and change the email address (Red words). Put in cgi-bin folder. But can't work. Error message: 500 Internal Server Error. My environment is "Apache Web Server 1.3.4, Perl 5.005_03. Why.

Kind Regards



 
Check your permissions, also check your weblogs, as these should have more information
hth
-Paul
 
Use Net::SMTP rather then sendmail, you'll be cross platform compatible.

 
The e-vangelist hath spake

Sib - with you on this one, at last

--Paul

It's important in life to always strike a happy medium, so if you see someone with a crystal ball, and a smile on their face ...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top