home *** CD-ROM | disk | FTP | other *** search
Wrap
#!/usr/bin/perl # Change above so it points to perl. Next line controls output buffering. $|=1; ######## # # E-mail contact form script, (c) Alex Cruickshank 2003 (alex@itreviews.co.uk) # # This code is released under the GNU Public Licence (see www.gnu.org for details) and is supplied # as is with no warranty either expressed or implied. No liability will be accepted for loss or damage of any kind. # # Always back up your data before using new software. # # You are free to use this script to manage and serve data on your site. # Please notify the author of any such use, as well as bug reports, modifications, etc. # # chmod this file to 755. This script requires sendmail. # $mail_prog = "/usr/sbin/sendmail"; # path to mail program, has to be sendmail or similar # $admin_email = "you\@yoursite.co.uk"; # target e-mail address; you must place a '\' before the '@' symbol # $maintitle = "Contact us"; # title for every page # $cgi_file = "/cgi-bin/contact.cgi"; # relative URL of this script # $HeaderFile = "head.htm"; # HTML header file path # $FooterFile = "foot.htm"; # HTML footer file path # ######## &parse; print "Content-type: text/html\n\n"; if ($FORM{'message_in'}) {&send_message;} else {&main;} exit; sub parse { # handle form data 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; if ($FORM{$name}) { $fields{$name} = $fields{$name}.",".$value; } else { $FORM{$name} = $value; } } } sub header { # load and use a formatted page header open (HEADER,"$HeaderFile"); @header = <HEADER>; close (HEADER); foreach $headerline (@header) { print "$headerline"; } print "<H1>$maintitle</H1>\n"; } sub footer { # load and use a formatted page footer open (FOOTER,"$FooterFile"); @footer = <FOOTER>; close (FOOTER); foreach $footerline (@footer) { print "$footerline"; } } sub main { # show the form page &header; print<<"OUTPUT"; <P> Please use the form below to contact us. </P> <form action="$cgi_file" method="POST"> <input type="hidden" name="message_in" value="message_in"> <P>Your e-mail address:<BR><input type="text" size="50" name="your_address"></P> <P>The message subject (e.g. 'feedback', 'advertising', etc.):<BR><input type="text" size="50" name="your_subject"></P> <P>Enter the message:</P> <textarea name="new_mail" rows="15" cols="50" WRAP="VIRTUAL" style="font-family:arial, helvetica, sans-serif; color:#000000; font-size:10pt;"></textarea> <P><input type="submit" name="B1" value="Send"></P> </form> OUTPUT &footer; exit; } sub send_message { # do the e-mail sending &header; $from_email = lc($FORM{'your_address'}); $your_subject = $FORM{'your_subject'}; @message_body = $FORM{'new_mail'}; if ($from_email ne "") { if ($your_subject ne "") { if ($FORM{'new_mail'} ne "") { open(MAIL,"|$mail_prog -t"); print MAIL "To: $admin_email\n"; print MAIL "From: $from_email\n"; print MAIL "Return-Path: $from_email\n"; print MAIL "Reply-To: $from_email\n"; print MAIL "Subject: $your_subject\n\n"; foreach $mline (@message_body) { print MAIL "$mline"; } close (MAIL); } else { print "<P>Your form was not complete (no message). Please go back and try again.</P>\n"; &footer; exit; } } else { print "<P>Your form was not complete (no subject). Please go back and try again.</P>\n"; &footer; exit; } } else { print "<P>Your form was not complete (no e-mail address). Please go back and try again.</P>\n"; &footer; exit; } print "<P>Thank you. Your message has been received, and will be read soon.</P><P>Now please click on one of the links on this page to visit another part of the site.</P>\n"; &footer; exit; }