#!/usr/bin/perl # AUTHOR - This script is a modified version of Ben Hare's EmailIt script. # Modifications Made by Michael Wu on behalf of Spirituality # & Health Magazine. Please do not use without permission. Ben's copyright is below: # # EmailIt! may be used and modified free of charge by anyone so long as this # copyright notice and copyright notices displayed in all HTML output of the # program remain intact. This program uses # several modified routines from Matt Wright's FormMail program - See # copyright notice for FormMail at end of page. # By using this code you agree to indemnify Ben Hare from any liability that # might arise from its use. require 'variables.pl'; $version = "1.01"; print "Content-type:text/html\n\n"; if (!$ENV{'HTTP_REFERER'}) { print "This script cannot be acessed directly.\n"; print "\n"; print "This script cannot be accessed directly.\n"; print "To run the script you need to create a link to it on a web page, then access\n"; print "it via the link. That page will be the page the script sends.\n\n"; exit; } if ($ENV{'REQUEST_METHOD'} eq 'GET') { @pairs = split(/&/, $ENV{'QUERY_STRING'}); } elsif ($ENV{'REQUEST_METHOD'} eq 'POST') { read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); @pairs = split(/&/, $buffer); } else { print "Bad request method\n"; } foreach $pair (@pairs) { local($name, $value) = split(/=/, $pair); $name =~ tr/+/ /; $name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $value =~ s///g; if ($FORM{$name} && $value) { $FORM{$name} = "$FORM{$name}, $value"; } elsif ($value) { $FORM{$name} = $value; } } if ($FORM{'action'} eq "sendit") { &check_url; &sendit; &returnhtml; } elsif ($FORM{'action'} eq "refer") { &check_url; &main; } elsif ($FORM{'action'} eq "README") { &readme; } else { &check_url; &main; } sub main { if ($FORM{'url'} eq "") { $sendpage = $ENV{'HTTP_REFERER'}; } else { $sendpage = $FORM{'url'}; } $namepage = $FORM{'name'}; print < EOF ; } print <
Email a Friend
EOF ; if ($allowuseredit) { print < EOF ; } else { print < EOF ; } print <
Fill out the form below to forward the following page:
$namepage



Recipient's Name:
Recipient's
Email Address(es):

Note: use commas to separate
multiple email addresses.
Your Name:
Your Email Address:

Message Subject:
Message:
Message Subject: $FORM{'title'}
Message: Thought you might be interested in reading this web page: $sendpage
 


Spirituality & Health will not collect or use the email addresses you provide for any purpose other than for sending this message. For more information, read our privacy policy.
EOF ; if ($usefooter) { &footer; } else { print < 

 

EOF ; } print < EOF ; exit; } sub sendit { if (($FORM{'frommail'} =~ /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/) || ($FORM{'frommail'} !~ /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/) || ($FORM{'toname'} eq "") || ($FORM{'fromname'} eq "") || ($FORM{'message'} eq "") ) { print < EOF ; } print <
Email a Friend
EOF ; if ($allowuseredit) { print < EOF ; } else { print < EOF ; } print <
Missing fields or bad email address(es) detected. Please double check the information below:

Recipient's Name:
Recipient's Email Address(es):
Note: use commas to separate multiple email addresses.
Your Name:
Your Email Address:
Message Subject:
Message:
Message Subject: $FORM{'subject'}
Message: $FORM{'message'}
 
 
EOF ; if ($usefooter) { &footer; } else { print < 

 

EOF ; } print < EOF ; exit; } else { # Open The Mail Program open(MAIL,"|$mailprog -t"); print MAIL "To: $FORM{'tomail'}\n"; print MAIL "From: $FORM{'frommail'} ($FORM{'fromname'})\n"; print MAIL "Subject: $FORM{'subject'}\n\n"; print MAIL "Hi $FORM{'toname'}!\n\n"; print MAIL $FORM{'message'}; print MAIL "\n\n"; print MAIL "Regards,\n\n"; print MAIL "$FORM{'fromname'}\n\n"; open(PROMO,"/var/www/vhosts/spiritualityhealth.com/httpdocs/newsh/promo.txt"); @promo = ; close(PROMO); foreach $line(@promo) { print MAIL "$line"; } print MAIL "\n\n"; close (MAIL); } if ($sendthankyou) { open(MAIL2,"|$mailprog -t"); print MAIL2 "To: $FORM{'frommail'}\n"; print MAIL2 "From: $adminmail ($adminname)\n"; print MAIL2 "Subject: Thanks for recommending $sitename!\n\n"; if ($customthankyou) { open(LIST,"$path/thankyou.txt"); @thankyou = ; close(LIST); foreach $line(@thankyou) { print MAIL2 "$line"; } print MAIL2 "\n\n"; open(PROMO,"/var/www/vhosts/spiritualityhealth.com/httpdocs/newsh/promo.txt"); @promo = ; close(PROMO); foreach $line(@promo) { print MAIL2 "$line"; } print MAIL2 "\n\n"; } else { print MAIL2 "Hi $FORM{'fromname'}!\n\n"; print MAIL2 "Thanks for recommending our services - we appreciate it!\n\n"; print MAIL2 "Best Regards,\n\n"; print MAIL2 "$adminname\n"; print MAIL2 "$sitename\n"; print MAIL2 "$siteURL\n\n"; } close (MAIL2); } if ($notifyadmin) { open(MAIL3,"|$mailprog -t"); print MAIL3 "To: dan\@spiritualityhealth.com\n"; print MAIL3 "From: $adminmail\n"; print MAIL3 "Subject: $FORM{'name'} \n\n"; print MAIL3 "Sender: $FORM{'fromname'} ( $FORM{'frommail'} )\n\n"; print MAIL3 "Recipient: $FORM{'toname'} ( $FORM{'tomail'} )\n\n"; print MAIL3 "Page: $FORM{'url'} \n\n"; close (MAIL3); } } sub returnhtml { #Then print out response page if ($noredirect) { print < $sitename: Message Sent EOF ; if ($useheader) { &header; } else { print < EOF ; } print <Message Sent!

Thanks $FORM{'fromname'}! Your message has been sent to $FORM{'toname'}. Click here to return to our homepage.

 

 

EOF ; if ($usefooter) { &footer; } else { print < 

 

EOF ; } print < EOF ; } else { print < $sitename: Message Sent!

Message Sent!

Thanks $FORM{'fromname'}! Your message has been sent to $FORM{'toname'}. Now forwarding you back to the page you emailed...

 

 

EOF ; } exit; } #the following check_referer routine written by Matt Wright. #see copyright notice below. sub check_url { # Localize the check_referer flag which determines if user is valid. # local($check_referer) = 0; # If a referring URL was specified, for each valid referer, make sure # # that a valid referring URL was passed to FormMail. # if ($ENV{'HTTP_REFERER'}) { foreach $referer (@referers) { if ($ENV{'HTTP_REFERER'} =~ m|https?://([^/]*)$referer|i) { $check_referer = 1; last; } else { # print "
" . $referer; } } } else { $check_referer = 1; } # If the HTTP_REFERER was invalid, send back an error. # if ($check_referer != 1) { print < $sitename: Bad Referer EOF ; if ($useheader) { &header; } else { print < EOF ; } print <Bad Referer

The page attempting to access this program resides at $ENV{'HTTP_REFERER'}, which is not allowed to access this program. Any page linking to this program must reside at $ENV{'SERVER_NAME'}.

If you are trying to configure this program to run on your server, view the README file.


EOF ; if ($usefooter) { &footer; } else { print < 

 

EOF ; } print < EOF ; exit; } } sub readme { print < Page Not Found EOF ; exit; } sub header { if (-e "$path/header.txt") { open(HEAD,"$path/header.txt") || &error("can't open $path/header.txt for reading"); @header = ; close(HEAD); foreach $line(@header) { print "$line"; } } else { &error("header.txt does not exist"); } } sub footer { if (-e "$path/footer.txt") { open(FOOT,"$path/footer.txt") || &error("can't open footer.txt for reading"); @footer = ; close(FOOT); foreach $line(@footer) { print "$line"; } } else { &error("footer.txt does not exist"); } } sub error { my $error_msg = shift; print <
$error_msg EOF ; exit; } #Contains elements adapted from FormMail by Matt Wright ############################################################################## # FormMail Version 1.6 # # Copyright 1995-1997 Matt Wright mattw@worldwidemart.com # # Created 06/09/95 Last Modified 05/02/97 # # Matt's Script Archive, Inc.: http://www.worldwidemart.com/scripts/ # ############################################################################## # COPYRIGHT NOTICE # # Copyright 1995-1997 Matthew M. Wright All Rights Reserved. # # # # FormMail may be used and modified free of charge by anyone so long as this # # copyright notice and the comments above remain intact. By using this # # code you agree to indemnify Matthew M. Wright from any liability that # # might arise from its use. # # # # Selling the code for this program without prior written consent is # # expressly forbidden. In other words, please ask first before you try and # # make money off of my program. # # # # Obtain permission before redistributing this software over the Internet or # # in any other medium. In all cases copyright and header must remain intact # ##############################################################################