Gossamer Forum
Home : General : Perl Programming :

E-mail form question

Quote Reply
E-mail form question
I have been searching this and other sites looking for information on a particular type of form. The form I need is an information request and does this:

Input standard name, address, type info.

There are check blocks to check for different departments, i.e.
mother
father
son
daughter

If father is checked, the info will only be sent to father, and not the others, or if father and son are checked, it will send to both recipients, but not the others...

Any suggestions????

Can't never could do nothing till he whupped old couldn't till he could...
Quote Reply
Re: E-mail form question In reply to
Here is something i threw together, you can try it if you want;

#################################
HTML page code;

<html>

<head>
<meta http-equiv="Content-Language" content="en-gb">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>New Page 1</title>
</head>

<body>

<form method="POST" action="/cgi-bin/script.cgi">
<p>Your E-Mail Address : <input type="text" name="email" size="20"></p>
<p>Father     <input type="radio" value="father" name="sendto">

Mother   <input type="radio" value="mother" name="sendto">

Son        <input type="radio" value="son" name="sendto">

Daughter<input type="radio" value="daughter" name="sendto"></p>
<p>Subject : <input type="text" name="subject" size="20"></p>
<p>Comment :   <textarea rows="2" name="comment" cols="20"></textarea></p>
<p align="center"><input type="submit" value="Submit" name="B1"><input type="reset" value="Reset" name="B2"></p>
</form>

</body>

</html>


#############################################
END OF HTML CODE PAGE
#############################################


CGI PAGE CODE (e.g mail.cgi)

#!/usr/local/bin/perl


$fathermail = "father\@site.com";
$mothermail = "mother\@site.com";
$sonmail = "son\@site.com";
$daughtermail = "girl\@site.com";
$sendto = "$FORM{sendto}";

# Location of sendmail on your server
$sendmail = "/usr/sbin/sendmail";


if ($ENV{'REQUEST_METHOD'} eq 'GET') {
$buffer = $ENV{'QUERY_STRING'};
}
else {
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
}

# Break em up into a format the script can read

@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;
}

if ($sendto = "father") {
open (MAIL, "|$sendmail -t") or &dienice("Can't access $sendmail!\n");
print MAIL "To: $fathermail \n";
print MAIL "From: $FORM{email} \n";
print MAIL "Reply-to: $FORM{email} \n";
print MAIL "Subject: $FORM{subject} \n\n";
print MAIL "$FORM{comment}\n";
close(MAIL);
}

if ($sendto = "mother") {
open (MAIL, "|$sendmail -t") or &dienice("Can't access $sendmail!\n");
print MAIL "To: $mothermail \n";
print MAIL "From: $FORM{email} \n";
print MAIL "Reply-to: $FORM{email} \n";
print MAIL "Subject: $FORM{subject} \n\n";
print MAIL "$FORM{comment}\n";
close(MAIL);
}


if ($sendto = "son") {
open (MAIL, "|$sendmail -t") or &dienice("Can't access $sendmail!\n");
print MAIL "To: $sonmail \n";
print MAIL "From: $FORM{email} \n";
print MAIL "Reply-to: $FORM{email} \n";
print MAIL "Subject: $FORM{subject} \n\n";
print MAIL "$FORM{comment}\n";
close(MAIL);
}


if ($sendto = "daughter") {
open (MAIL, "|$sendmail -t") or &dienice("Can't access $sendmail!\n");
print MAIL "To: $daughtermail \n";
print MAIL "From: $FORM{email} \n";
print MAIL "Reply-to: $FORM{email} \n";
print MAIL "Subject: $FORM{subject} \n\n";
print MAIL "$FORM{comment}\n";
close(MAIL);
}


#####################################################
END OF CGI CODE
####################################################

I won't guarantee this will work, but its worth a try Cool

Yours

A.J.Newby
webmaster@ace-installer.com
http://www.ace-installer.com




Quote Reply
Re: E-mail form question In reply to
In Reply To:
<form method="POST" action="/cgi-bin/script.cgi">
That should be...

<form method="GET" action="/cgi-bin/script.cgi">


It wont work either because you have used...

$FORM{$name} = $value;

...but then used...

if ($sendto) {

Where has $sento come from?
You are getting mixed up with then names of the fields and the variables.

Give each field a different name...ie sendto1 sendto2 sendto3 sendto4

..then use...

$father = $FORM{sendto1};
$mother = $FORM{sendto2};
$son = $FORM{sendto2};
$daughter = $FORM{sendto2};

...then you can use;

if ($father) {
open (MAIL, "|$sendmail -t") or &dienice("Can't access $sendmail!\n");
print MAIL "To: $fathermail \n";
print MAIL "From: $FORM{email} \n";
print MAIL "Reply-to: $FORM{email} \n";
print MAIL "Subject: $FORM{subject} \n\n";
print MAIL "$FORM{comment}\n";
close(MAIL);
}

if ($mother) {
open (MAIL, "|$sendmail -t") or &dienice("Can't access $sendmail!\n");
print MAIL "To: $mothermail \n";
print MAIL "From: $FORM{email} \n";
print MAIL "Reply-to: $FORM{email} \n";
print MAIL "Subject: $FORM{subject} \n\n";
print MAIL "$FORM{comment}\n";
close(MAIL);
}


if ($son) {
open (MAIL, "|$sendmail -t") or &dienice("Can't access $sendmail!\n");
print MAIL "To: $sonmail \n";
print MAIL "From: $FORM{email} \n";
print MAIL "Reply-to: $FORM{email} \n";
print MAIL "Subject: $FORM{subject} \n\n";
print MAIL "$FORM{comment}\n";
close(MAIL);
}


if ($daughter) {
open (MAIL, "|$sendmail -t") or &dienice("Can't access $sendmail!\n");
print MAIL "To: $daughtermail \n";
print MAIL "From: $FORM{email} \n";
print MAIL "Reply-to: $FORM{email} \n";
print MAIL "Subject: $FORM{subject} \n\n";
print MAIL "$FORM{comment}\n";
close(MAIL);
}




Paul Wilson. Shocked
(Dont blame me if I'm wrong!)
Quote Reply
Re: E-mail form question In reply to
The form method doesn't matter in this case cos the form parsing i used works for both POST and GET.

A.J.Newby
webmaster@Ace-installer.com
http://www.ace-installer.com