Here is the HTML page (simple form).
and here is the cgi.
Code:
#!/usr/bin/perl
print "Content-type:text/html\n\n";
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@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 ($FORM{'fname'} eq "") {
&dienice("Please enter your friend's name.");
exit;
}
if ($FORM{'femail'} eq "") {
&dienice("Please enter friend's email address.");
exit;
}
if ($FORM{'sname'} eq "") {
&dienice("Please fill in your email address name.");
exit;
}
if ($FORM{'semail'} eq "") {
&dienice("Please enter your email address.");
exit;
}
print <<EndHead;
<html>
<head>
<title>Message Sent</title>
<link rel="StyleSheet" type="text/css" href="url to css">
</head>
<body bgcolor="#E1E1E1">
EndHead
$mailprog = '/usr/sbin/sendmail';
$recipient = "$FORM{'femail'}";
$from = "$FORM{'semail'}";
open (MAIL, "|$mailprog -t") or &dienice("Can't access $mailprog!\n");
print MAIL "To: $recipient\n";
print MAIL "From: $from\n";
print MAIL "Reply-to: $FORM{'semail'}\n";
print MAIL "Subject: Hey. Check this site out.\n\n";
print MAIL <<EndMAIL;
Hey $FORM{'fname'},
put your default message here. Don't forget to put the url of the page!
$FORM{'sname'}
EndMAIL
close(MAIL);
# now print something to the HTML page, usually thanking the person
# for filling out the form, and giving them a link back to your homepage
print <<EndHTML;
<font size="4"><b>Message Sent</b></font>
<p><a href="../email.html" target="_self">Click here</a> to send this page to another friend.
<br><br>[<a href="http://" onClick="javascript:window.close();">Close this window</a>]</p>
</body>
</html>
EndHTML
exit;
sub dienice {
my($msg) = @_;
print qq(
<html>
<head>
<title>Email this page to a friend</title>
<link rel="StyleSheet" type="text/css" href="url to css file">
</head>
<body bgcolor="#E1E1E1">
<font size="4">Error</font><p>\n);
print qq($msg <a href="http://" onClick="history.go(-1);" target="_self">Go back</a> and try again.\n);
print qq(</body></html>);
exit;
}
I named the html file email.html and placed the email.cgi script in my cgi-bin directory.
cheers!