# ADD ATTACHMENTS TO FORM # Set the attachment variables my $FileName; my $FileName2; my $FileName3; my $myFilePath; my $i; my @attachmentFiles; # Get the attachment $FileName = $query->param('FileName'); $FileName2 = $query->param('FileName2'); $FileName3 = $query->param('FileName3'); @attachmentFiles = (); # Put the attachments in an Array # This allows each file to be filtered through read and attached if( !defined($FileName) || $FileName ne "") { push (@attachmentFiles, $FileName); if( !defined($FileName2) || $FileName2 ne "") { push (@attachmentFiles, $FileName2); if( !defined($FileName3) || $FileName3 ne "") { push (@attachmentFiles, $FileName3); } } } #### sub admin_mailer { print DEBUG "in admin mailer...\n" if ($debug_log); $admin = $query->param('admin'); # If $email begins "test:" then we are in a test mode. Send # the admin e-mail to the specified e-mail address. if ( $email =~ /^test:/ ) { $email =~ s/^test\://; $admin = $email; } @sendary = split ( /,/, $admin ); if ( $query->param('admin_subject') ) { $subj = convertInputString( $query->param('admin_subject') ); } else { $subj = convertInputString( $query->param('subject') ); } print DEBUG "Admin mailer converting...\n"; my $email = convertInputString( $query->param('EMail') ); my $fname = convertInputString( $query->param('FirstName') ); my $lname = convertInputString( $query->param('LastName') ); my $from = $fname . " " . $lname . " <" . $email . ">"; # # Give the e-mail client a hint of what charset to # expect. Some clients may ignore but at least we # try to behave nicely. # #&logEvent("Mailing admins @sendary From: $fname $lname"); #open( MAIL, "|$MAILPROG @sendary" ) or die "Cannot open $MAILPROG: $!"; #print MAIL "MIME-Version: 1.0\n"; #if ( $inputCharset =~ /UTF\-8/i ) { # print DEBUG "Formatting Mail UTF-8\n" if ($debug_log); # print MAIL "Content-type: text/plain; charset=UTF-8\n"; #} #else { # print DEBUG "Formatting Mail ISO-8859-1\n" if ($debug_log); # print MAIL "Content-type: text/plain; charset=ISO-8859-1\n"; #} #print MAIL "Content-type: text/plain; charset=" . $outputCharset . "; \n"; #print MAIL "From: \"$fname $lname\"<$email>\n"; #print MAIL "To: $admin\n"; #print MAIL "Subject: $subj \n"; #print MAIL "\n"; #print MAIL ""; @names = $query->param; @namelist = split ( /,/, $query->param(admin_mailer_fields) ); print DEBUG "namelist : @namelist\n"; if (@namelist) { # Go through the form hash from loadFormHash and get the desired fields in the order of # admin_mailer_values foreach $name (@namelist) { $message_body = $message_body . $name . ": " . $HASH{$name} . "\n\n"; } } else { foreach $record ( keys(%HASH) ) { $message_body = $message_body . $record . ": " . $HASH{$record} . "\n\n"; } } ### Create the multipart container $msg = MIME::Lite->new ( From => $from, To => $admin, Subject => $subj, Type =>'multipart/mixed' ) or die "Error creating multipart container: $!\n"; ### Add the text message part $msg->attach ( Type => 'TEXT', Data => $message_body ) or die "Error adding the text message part: $!\n"; ### Add the file if(@attachmentFiles ne "" || @attachmentFiles ne "NULL"){ for ( $i = 0 ; $i < scalar ( @attachmentFiles ) ; $i++ ) { &openattachment; if($theirFile ne "NULL" || $theirFile ne "" ){ $msg->attach ( Type => 'AUTO', Path => $myFilePath, FileName => $FileName, Disposition => 'attachment' ); } } } ### Send the Message $msg->send; }