#!/usr/bin/perl
###########################################################################
# email.pl
# 200804, cbartels
#
# sends email with a link to the newsletter to the address provided
# replaces email.sfe written by jstrimpe, 10/2006
###########################################################################
#
BEGIN {
$debug = 0; # important that this is set before the use CGI_Input
$|=1; # output auto flush
use lib '/local/apache/htdocs-dah/news/newsletter';
}
use DAH_CGI_Input; # note this is a local copy for dah.
###########################################################################
# global vars
my $header = "header.html";
my $footer = "footer.html";
my $support = 'webmaster@soe.ucsd.edu';
my $mailsubject = "Link, an e-newsletter from UC San Diego's Division of Arts and Humanities";
my ($mailto,$mailfrom,$access,$bad_var);
@allowed_vars;
@required_vars;
$error_msg_text;
###########################################################################
# print header
print "Content-type: text/html\n\n";
###########################################################################
# Process incoming data
# decode and split input data
$Vars=DAH_CGI_Input::parse_indata(); # $Vars is a ref to hash
##########################################
# Assign values to variable names
while ( ($name,$value) = each(%$Vars) ) {
# # remove either quote character from data values (since these
# # would require special handling to do the sybase insert).
# $value =~ s/'|"//g;
$$name = $value;
if ($debug) {print "$name equals $$name
\n";}
}
#########################################
# Check variables passed in
# these are the only variables allowed; reject if they send anything else.
@allowed_vars = qw(SendToEmail SendFromEmail SendBodyEmail submit);
$bad_var = DAH_CGI_Input::allowed_vars(\@allowed_vars, $Vars);
if ($bad_var) {
$error_msg_text = "Rejected Submission -- Bad Variable Passed: $bad_var";
DAH_CGI_Input::error_form("Bad Variable");
} elsif ($debug) {
print "All vars OK
\n";
}
#########################################
# set this var now; used below in required var check
# what are we doing? submitting the form or just displaying it?
if ($SendToEmail && $SendToEmail ne "") {
$access = "SendMail";
} else {
$access = "ShowForm";
}
#########################################
# Check for required variables --
# dependent upon value of $access set above
if ($access eq "SendMail") {
@required_vars = qw(SendToEmail SendFromEmail SendBodyEmail);
} else {
@required_vars = qw();
}
($missing_vals) = DAH_CGI_Input::required_vars(\@required_vars,0); # ref to array
if ($missing_vals) {
for ($i=0;$i<@$missing_vals;++$i) {
$missing_vals_html .= "
" . uc(@$missing_vals[$i]);
}
$error_msg_text = "You must supply data for the following field(s): $missing_vals_html";
DAH_CGI_Input::error_form("Missing Values");
} elsif ($debug) {
print "OK - No Missing Vals
\n";
}
###########################################################################
# Check variable values
if ($debug) {
print "DEBUGGING IS TURNED ON...
\n";
}
#######################################################
if ($access eq "SendMail") {
send_email();
}
print_page();
#######################################################
#######################################################
# SUBROUTINES
#######################################################
#######################################################
sub print_page {
open (HDR,"$header") || warn "Cannot Open Form Header\n";
while ( Mail Newsletter to a Friend
Your message and a link to the newsletter has been sent to
the email address you entered into the form.
« Back to Newsletter