#!/usr/bin/perl -wT
###################
#Create new object of type CGI
####################
use CGI;
use MIME::Lite;
$query = new CGI;
#####################
#grab text #
#####################
print "Content-type: text/html\n\n";
$cc = $query->param("Ccemail");
$from = $query->param("From");
$subject = $query->param("Subject");
$comment = $query->param("Comment");
$file = $query->param("Attach");
@list = $query->param("list");
@name = split(/\\/, $file); #finds all /'s
# $name = $name[$#name]; #finds last / and assumes name is afterward
$name = $name[$#name]; #finds last / and assumes name is afterward
# my $FILE = "/home/wsc13/pub_html/Academic_Progs/CAS/afrotc/public_html/tmp/";
my $FILE = "/home/canto8/~afrotc/public_html/tmp2/";
my $type = "application/octet-stream";chmod
$list=join(",", @list);
###################
#Mail form #
###################
@extension = split(/\./, $name);
$extension = $extension[$#extension];
# These file types should be okay:doc, docx, gif, jpg, pdf, ppt, txt, xls
# allowed file types to upload
@goodfiles = ("doc","docx","gif","jpg","pdf","ppt","txt","xls","rtf","odt","zip");
&fileopen;
sub fileopen {
open(UPLOAD, "+>$FILE/$name") or print "Sorry, cannot open $FILE: $!
";
my ($data, $chunk);
while ($chunk = read($file, $data, 1024))
{
print UPLOAD $data;
}
close(UPLOAD) or print "Cannot close $FILE: $!
";
#chmod(0777, "$FILE") or print "Cannot chmod $FILE: $!
";
# $msg = "You attached file $name";
my $mime_msg = MIME::Lite->new(
From => $from,
To => $list,
Cc => $cc,
Subject => $subject,
Type => 'text/plain',
Data => $comment
);
# JMD: Need to have mimetype and encoding type
my ($mime_type, $encoding) = ('application/octet-stream','base64');
# Attach the file
$mime_msg->attach(
Type => $type,
# JMD: Seems to only work this way, without Filename attritbute, don't know why.
Path => "$FILE$name",
Disposition => 'attachment'
) or dienice("Cannot upload attachment: $!");
#MIME::Lite->send('sendmail', "/usr/lib/sendmail -t -oi -oem");
$mime_msg->send();
print "$_
";
unlink($FILE);
}
sub Error {
die "No File uploaded or incorrect filetype";
}
#############################################
#Printing a message to the user
#############################################
print "Content-type: text/html\r\n\r\n";
print "Emailing the following content: \n\n";
print "$comment \n\nAttachment:$name \n";
#print "$msg\n";
print "To: $list\n";
#print "This is the query file:\n $query\n";
#############################################
#Mailing construct
############################################