|
|
EOH
&eXit;
}
sub sendMail {
my ($args) = @_;
my @errors;
my $recipList;
my $who;
my $fromname = $$args{fromname};
my $fromemail = $$args{fromemail};
my $message = $$args{message};
my $subject = $$args{subject};
my $toAlums = $$args{toalums};
my $toActvs = $$args{toactvs};
my $toWbmst = $$args{towbmst};
if (!$fromname || $fromname =~ /^\s+$/) {
push(@errors, "Please Enter Your Name");
}
if ($fromemail !~ /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/) {
push(@errors, "You Need to Enter a Valid Email Address");
} else {
if (!Email::Valid->address(-address =>$fromemail,-mxcheck => 1)) {
push(@errors, "Sorry, That Does Not Seem To Be A Valid Email Address");
}
}
if (!$subject || $subject =~ /^\s+$/) {
push(@errors,"You Gotta Enter a Subject for your Email");
}
if (!$message || $message =~ /^\s+$/) {
push(@errors,"You didn't enter anything in the message text box");
}
if (length($message) > 5000) {
push(@errors,"Message Length Cannot Exceed 5000 Characters");
}
if (!$toAlums && !$toActvs && !$toWbmst) {
push(@errors, "You Must Check at Least One Recipient");
}
if (@errors) {
&MailErrors($args,@errors);
return;
}
my $dbh;
if ($toActvs) {
$dbh = &dbConnect;
my $stmt = "select first, last, email, pin, priv from members
where status = 'A'
and
priv > ' '
and
email like '%@%'
order by pin desc";
my $sth = $dbh->prepare($stmt);
$sth->execute || die "error executing statement $stmt\n";
while ( my ($first,$last,$email,$pin,$priv) = $sth->fetchrow_array ) {
if ($priv =~ /[EFGMLNOPQRrSsTtYZi]/i) {
my $name = "$first $last";
$name =~ s/\s+/ /g;
$recipList .= "$email ($name),";
}
}
$who = "\tAll Active Officers\n";
}
if ($toAlums) {
$dbh ||= &dbConnect;
my $stmt = "select first, last, email, pin, priv from members
where (priv like '%H%' or pin = 315)
and
email like '%@%'
order by pin desc";
my $sth = $dbh->prepare($stmt);
$sth->execute || die "error executing statement $stmt\n";
while ( my ($first,$last,$email,$pin,$priv) = $sth->fetchrow_array ) {
my $name = "$first $last";
$name =~ s/\s+/ /g;
$recipList .= "$email ($name),";
}
#$recipList .= 'HouseCorp@SigmaNuSDSU.com (House Corp),';
$who .= "\tHouse Corp Members\n";
}
if ($toWbmst) {
$recipList .= 'WebMaster@SigmaNuSDSU.com (SigmaNuSDSU WebMaster)';
$who .= "\tWebMaster (HK315)\n";
}
$recipList =~ s/,$//;
my $ipInfo = "IP Address of Sender: $ENV{REMOTE_ADDR}, Host: $ENV{REMOTE_HOST}";
if ($ipInfo =~ /\b12\.1/) {
$ipInfo = '';
}
if ($recipList) {
open (MAIL, "|$mailprog -t -f WebMaster\@SigmaNuSDSU.com") || die "Can't open $mailprog!\n";
print MAIL "From: $fromemail ($fromname)\n";
print MAIL "To: $recipList\n";
if (!$toWbmst) {
print MAIL "BCC: SigmaNuWebmaster\@gmail.com\n";
}
print MAIL "Subject: SigmaNu: $subject\n\n";
print MAIL <