Gossamer Forum
Home : Products : DBMan : Customization :

Email Attachments - Again ;(

Quote Reply
Email Attachments - Again ;(
I've spent hours on this one little task: to attach a file to the mass mailer form. I'm trying to attach a word document to start with. I've followed many of the posts in several different forums and I'm still not making much progress. Here is what happens:

Mass Mailer Form - if I add

<FORM ENCTYPE="multipart/form-data" action="$db_script_url" method="POST">

...the mass mailer fails in a very bizarre way (it sends me back to the administrator login screen. However, if I leave off the ENCTYPE attribute, the mass-mailer completes, sends the attachment, but it is empty. I believe the ENCTYPE is necessary to load from the PC. Set me straight if that isn't the case.

Here the pieces:

sub html_mass_mail_form {
...
print qq|<form action="$db_script_url" method="POST"ENCTYPE="multipart/form-data">
<input type=hidden name="db" value="$db_setup">
<input type=hidden name="uid" value="$db_uid">
...
}


sub mass_mail {
# --------------------------------------------------------
#
use MIME::Base64 qw(encode_base64);

my ($i,$message,@lines,$line,$count,%rec,$mail_count);
my @boundaryv = (0..9, 'A'..'F');
srand(time ^ $$);
for (my $i = 0; $i++ < 24;) {
$boundary .= $boundaryv[rand(@boundaryv)];
}

&auth_logging('Starting Mass Mailer', $userid) if ($auth_logging);
unless ($admin_email) { $message = "Admin email has not been entered in the .cfg file<BR>"; }
unless ($admin_email =~ /.+\@.+\..+/) { $message = "Admin email address is not in the correct format.<BR>"; }
unless ($in{'subject'}) { $message .= "You must fill in a subject for your message.<BR>"; }
unless ($in{'emailmessage'}) { $message .= "Your email message is empty.<BR>"; }
unless ($in{'email'}) { $message .= "Your email address is empty.<BR>"; }
for ($i = 0; $i <= $#db_cols; $i++) {
if ($db_email_field eq $db_cols[$i]) {
$found = 1;
last;
}
}
if (!$found) {
$message .= "email field not found<BR>";
}
open (DB, "<$db_file_name") or &cgierr("error in mass_mail. unable to open database: $db_file_name.\nReason: $!");
@lines = <DB>;
close DB;
$in{'mh'} = $#lines;
my ($status, @hits) = &query("view");
unless ($status eq 'ok') {
$message .= "$status<BR>";
}
if ($message) {
chomp($message);
&html_mass_mail_form($message);
return;
}
my ($numhits) = ($#hits+1) / ($#db_cols+1);
for (0 .. $numhits - 1) {
%rec = &array_to_hash($_, @hits);
if ($rec{$db_email_field} =~ /.+\@.+\..+/)
{

my $mail = "/usr/lib/sendmail -t -i";
open(MAIL,"|$mail");

print MAIL "To: $rec{$db_email_field}\n";
print MAIL "From: $in{'email'}\n";
print MAIL "Subject: $in{'subject'}\n";
print MAIL "mime-Version: 1.0\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/plain; charset=us-ascii\n";
print MAIL "Content-Transfer-Encoding: 7bit\n\n";
print MAIL "$in{'emailmessage'}\n\n";
print MAIL "\n";
print MAIL "--------------$boundary\n";
print MAIL "Content-Type: application/msword; name=\"$in{'file'}\"\n";
print MAIL "Content-Disposition: inline; filename=\"$in{'file'}\"\n";
print MAIL "Content-Transfer-Encoding: base64\n\n";
print MAIL "\n--------------$boundary--\n";

my $buf;
$/=0;
open (INPUT, "$file") or die ("Can't find file");
while(read(INPUT, $buf, 60*57)) {
print MAIL &encode_base64($buf);
}

close INPUT;
print MAIL "\n--------------$boundary--\n";
print MAIL "\n";
close MAIL;

++$mail_count;
push (@sent_to,$rec{$db_email_field});
}
}
&html_mass_mail_success($mail_count,@sent_to);
}

What am I doing wrong??????

Dazed and Confused.