
monocle
User
Jun 14, 2000, 10:34 PM
Post #2 of 3
(2253 views)
|
Re: Send Page to a friend script
[In reply to]
|
Can't Post
|
|
I use this one. It can handle 10 recipients and has required field checking. <BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR> #!/usr/bin/perl ############################################################################## # # # This script is called with a link on your page you want sent to a friend. # # # # Place the following line on your page. # # <a href="/cgi-bin/sendtofriend.cgi">Tell a Friend</a> # # # ############################################################################## # Define Variables # # # $mailprog = '/bin/sendmail'; $cgi_script = 'sendtofriend.cgi'; read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); $URL = $ENV{'HTTP_REFERER'}; # 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; $name =~ tr/+/ /; $name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $FORM{$name} = $value; } if($FORM{'URL'} eq ""){ print "Content-type: text/html\n\n"; &print_head; &print_form; } else { if ($FORM{'subject'} eq "") { push(@errors,"You must enter a subject for your email"); } if ($FORM{'username'} eq "") { push(@errors,"You must enter your email address"); } else { if ($FORM{'username'} !~ /(\w+)@(\w+)\.(\w+)/) { push(@errors,"You must enter a valid email address"); } if ($FORM{'username'} =~ m|([%$\/#*^&;`/])|i) { push(@errors,"You entered illegal characters in your email address"); } } if (!$FORM{'recipient1'} and !$FORM{'recipient2'} and !$FORM{'recipient3'} and !$FORM{'recipient4'} and !$FORM{'recipient5'} and !$FORM{'recipient6'} and !$FORM{'recipient7'} and !$FORM{'recipient8'} and !$FORM{'recipient9'} and !$FORM{'recipient10'}) { push(@errors,"You must enter at least one recipient email address"); } else { $rep_num = 1; while ($rep_num < 11) { $this_rep = "recipient$rep_num"; if (($FORM{$this_rep}) and ($FORM{$this_rep} !~ /(\w+)@(\w+)\.(\w+)/)) { push(@errors,"You entered an valid email address for recipient $rep_num"); } if (($FORM{$this_rep}) and ($FORM{$this_rep} =~ m|([%$\/#*^&;`/])|i)) { push(@errors,"You entered illegal characters in the email address for recipient $rep_num"); } $rep_num++; } } if (scalar(@errors) != "0") { $URL = $FORM{'URL'}; print "Content-type: text/html\n\n"; &print_head; print qq~ <div align="center"><center> <table border="0"> <tr> <td> <font face="arial,helvetica"><b>The following errors were encountered:<b></font> ~; foreach (@errors) { print "<li><b><font color=\"red\" face=\"arial, helvetica\" size=\"\-1\">$_</font></b>\n"; } print qq~ </td> </tr> </table> </center></div> <p> ~; &print_form; exit; } $rep_num = 1; while ($rep_num < 11) { $this_rep = "recipient$rep_num"; if ($FORM{$this_rep}){ $whoto = $FORM{$this_rep}; # Open The Mail open (MAIL, "|$mailprog -t") | | &safe_die("Can't open $mailprog!\n"); print MAIL "From: $FORM{'username'}\n"; print MAIL "Reply-To: $FORM{'username'}\n"; print MAIL "To: $whoto\n"; print MAIL "Subject: $FORM{'subject'}\n\n"; print MAIL "----------------------------------------------------------------------------------------\n\n"; print MAIL "$FORM{comment}\n\n"; print MAIL "$FORM{'URL'}\n\n"; close (MAIL); } $rep_num++; } print "Location: $FORM{URL}\n\n"; } sub print_head{ print <<"ENDHtml"; <html> <head> <title>Web Sender</title> </head> <body bgcolor="#FFFFFF" text="#000000" link="#000099" vlink="#000066" alink="#660000"> ENDHtml } sub print_form{ print <<"ENDHtml"; <div align="center"><center><font face="Arial,Helvetica"><b>Tell a friend about<br>$URL</b></font><br> <form action="$cgi_script" method="POST"> <table border="0" cellpadding="5" cellspacing="2" align="center"> <tr> <td align="right" NOWRAP> <b><font face="Arial,Helvetica" size=-1>Enter a subject<BR>for your email.</font></b> </td> <td> <font face="Arial,Helvetica" size=-1 color="#E0E0C2">10.</FONT><input type="text" name="subject" value="$FORM{'subject'}"> <B><font face="Arial,Helvetica" size=3 color="#FF0000">*</font></B> </td> </tr> <tr> <td align="right" NOWRAP> <b><font face="Arial,Helvetica" size=-1>Please enter your<BR>email address.</font></b> </td> <td> <font face="Arial,Helvetica" size=-1 color="#E0E0C2">10.</FONT><input type="text" name="username" value="$FORM{'username'}"> <B><font face="Arial,Helvetica" size=3 color="#FF0000">*</font></B> </td> </tr> <tr> <td align="right" NOWRAP> <b><font face="Arial,Helvetica" size=-1>Please enter the<BR>email address(es)<BR>of your friend(s).</font></b> </td> <td> <table border="0" cellpadding="0" cellspacing="0"> <tr> <td align="right"><font face="Arial,Helvetica" size=-1>1.</FONT></td> <td><input type="text" name="recipient1" value="$FORM{'recipient1'}"> <B><font face="Arial,Helvetica" size=3 color="#FF0000">*</font></B></td> </tr> <tr> <td align="right"><font face="Arial,Helvetica" size=-1>2.</FONT></td> <td><input type="text" name="recipient2" value="$FORM{'recipient2'}"></td> <tr> <td align="right"><font face="Arial,Helvetica" size=-1>3.</FONT></td> <td><input type="text" name="recipient3" value="$FORM{'recipient3'}"></td> <tr> <td align="right"><font face="Arial,Helvetica" size=-1>4.</FONT></td> <td><input type="text" name="recipient4" value="$FORM{'recipient4'}"></td> <tr> <td align="right"><font face="Arial,Helvetica" size=-1>5.</FONT></td> <td><input type="text" name="recipient5" value="$FORM{'recipient5'}"></td> <tr> <td align="right"><font face="Arial,Helvetica" size=-1>6.</FONT></td> <td><input type="text" name="recipient6" value="$FORM{'recipient6'}"></td> <tr> <td align="right"><font face="Arial,Helvetica" size=-1>7.</FONT></td> <td><input type="text" name="recipient7" value="$FORM{'recipient7'}"></td> <tr> <td align="right"><font face="Arial,Helvetica" size=-1>8.</FONT></td> <td><input type="text" name="recipient8" value="$FORM{'recipient8'}"></td> <tr> <td align="right"><font face="Arial,Helvetica" size=-1>9.</FONT></td> <td><input type="text" name="recipient9" value="$FORM{'recipient9'}"></td> <tr> <td align="right"><font face="Arial,Helvetica" size=-1>10.</FONT></td> <td><input type="text" name="recipient10" value="$FORM{'recipient10'}"></td> </tr> </table> </td> </tr> <tr> <td align="right" NOWRAP> <b><font face="Arial,Helvetica" size=-1>Add your<BR>comments</font></b> </td> <td> <TEXTAREA COLS="50" ROWS="10" NAME="comment" WRAP="soft">$FORM{'comment'}</TEXTAREA> </td> </tr> </table> <B><font face="Arial,Helvetica" size=2 color="#FF0000">* Required Field</font></b><BR><BR> <INPUT TYPE="submit" VALUE="Send Email"> <INPUT TYPE="reset" VALUE="Reset Form"> <INPUT TYPE="hidden" NAME="URL" VALUE="$URL"> </form> </center></div> </body> </html> ENDHtml } exit (0); </pre><HR></BLOCKQUOTE> Monocle Hear great techno by Monocle at http://www.mp3.com/monocle . CD now on sale!
|