Hi,
I am trying to write a script that attach's a file from the senders local drive and emails it to and address.
It kind of works but the file is either garbled or empty! and some files dont even attach or send the email.
The idea is that a visitor could send a log file from there system via email to our support centre via the web.
Here is the part of the script that should deal with the mail and the attachment.
you can try the code at this will email the same address that you put into the form.
Thanks for your help in advance.
Kind Regards, Paul Benn
**** Never Giveup, keep trying, the answer is out there!!! ****
I am trying to write a script that attach's a file from the senders local drive and emails it to and address.
It kind of works but the file is either garbled or empty! and some files dont even attach or send the email.
The idea is that a visitor could send a log file from there system via email to our support centre via the web.
Here is the part of the script that should deal with the mail and the attachment.
you can try the code at this will email the same address that you put into the form.
Code:
sub send_message
{
## Send File to poster Start
my @boundaryv = (0..9, 'A'..'F');
srand(time ^ $$);
for (my $i = 0; $i++ < 24;)
{
$boundary .= $boundaryv[rand(@boundaryv)];
}
open MAIL, "|$mailprog -t";
print MAIL "To: $email_address ($yourname)\n";
print MAIL "From: $email_address ($your_name)\n";
print MAIL "MIME-Version: 1.0\n";
print MAIL "Subject: $fileinfo\n";
print MAIL "Content-Type: multipart/mixed; boundary=\"------------$boundary\"\n";
print MAIL "\n";
print MAIL "This is a multi-part message in MIME format.\n";
print MAIL "--------------$boundary\n";
print MAIL "Content-Type: text/html; charset=us-ascii\n";
print MAIL "Content-Transfer-Encoding: 7bit\n\n";
print MAIL "<b>Dear $toname,\n\n</b><br><br>\n";
print MAIL "<br>Here is my file<br><br>File Attached: <b>$filename</b><br><br>\n";
print MAIL "<br><br>\n";
print MAIL "--------------$boundary\n";
## Attach the file
&attach_files;
print MAIL "\n--------------$boundary--\n";
print MAIL "\n";
close (MAIL);
$status = "Sent";
&okay_html;
}
sub attach_files {
$file=$attachment;
($ext) = $file =~ m,\.([^\.]*)$,;
$ext =~ tr,a-z,A-Z,;
$fext=&mimetype($ext);
print MAIL "--------------$boundary\n";
print MAIL "Content-Type: $fext; name=\"$atachment\"\n";
print MAIL "Content-Transfer-Encoding: base64\n";
print MAIL "Content-Disposition: attachment; filename=\"$filename\"\n\n";
&buf_type;
print MAIL "Content-Type: text/html; charset=us-ascii\n";
print MAIL "Content-Transfer-Encoding: 7bit\n\n";
print MAIL "File: $filename Attached";
print MAIL "--------------$boundary--\n";
}
sub buf_type {
my $buf2;
$/=0;
open INPUT, "$file";
binmode INPUT if ($^O eq 'NT' or $^O eq 'MSWin32');
while(read(INPUT, $buf2, 60*57))
{
print MAIL &encode_base64($buf2);
}
}
sub encode_base64 #($)
{
my ($res, $eol, $padding) = ("", "\n", undef);
while (($_[0] =~ /(.{1,45})/gs))
{
$res .= substr(pack('u', $1), 1);
chop $res;
}
$res =~ tr#` -_#AA-Za-z0-9+/#; # ` help emacs
$padding = (3 - length($_[0]) % 3) % 3; # fix padding at the end
$res =~ s#.{$padding}$#'=' x $padding#e if $padding; # pad eoedv data with ='s
$res =~ s#(.{1,76})#$1$eol#g if (length $eol); # lines of at least 76 characters
return $res;
}
Thanks for your help in advance.
Kind Regards, Paul Benn
**** Never Giveup, keep trying, the answer is out there!!! ****