#!/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 () { print "$_\n"; } close(HDR); print '

Mail Newsletter to a Friend

 

 

 

'; # end print if ($access eq "ShowForm") { print '
Recipient\'s Email Address:
Your Email Address:
Email addresses will NOT be collected, stored, or used in any way.
Message:

« Back to Newsletter

'; # end print } else { print '

Your message and a link to the newsletter has been sent to the email address you entered into the form.
« Back to Newsletter

'; # end print } # end check for ShowForm open (HDR,"$footer") || warn "Cannot Open Form Footer\n"; while () { print "$_\n"; } close(HDR); print ""; } # end print_page ####################################################### # Send email with form values. sub send_email { if (open (MAIL, "|/usr/lib/sendmail -t -oi" )) { print MAIL "From: $SendFromEmail \n"; print MAIL "To: $SendToEmail \n"; print MAIL "Subject: $mailsubject\n"; print MAIL "$SendBodyEmail\n"; print MAIL "http://dah.ucsd.edu/news/newsletter/"; print MAIL "\n"; close MAIL; } else { $error_msg_text = " The form you filled out could not be mailed.
Please contact webmaster "; DAH_CGI_Input::error_form("Mail Error"); } } #######################################################