[ back to toc ]

$SubjectHeading

Date: 2002/02/20 10:05

Q:
I've written this script that sends mass email to a local hs rugby club.
it works for sending text but how would I send off a jpg file along with
it as an attachment? I'm having trouble finding documentation for this
function on the web.

#!/usr/bin/perl -w
$mail_prog = '/usr/lib/sendmail' ;

open (FD,"< livonia_rugby_email.txt");
@address=<FD>;
close FD;

&GetFormInput;

$name = $field{'name'} ;
$EmailAddress = $field{'EmailAddress'} ;
$SubjectHeading = $field{'SubjectHeading'} ;
$comments = $field{'comments'} ;

$message = "" ;
$found_err = "" ;

if (($comments eq "") || ($name eq "") || ($EmailAddress eq "") or
($SubjectHeading eq "" )) {
print "Content-type: text/html\n\n";
print "Please fill in all fields in the form.";
exit;

}

$nl_sub = ' <br>' ;
$comments =~ s/\n/$nl_sub/g ;

open (MAIL, "|/usr/sbin/sendmail -t") || return 0;

select (MAIL);
print <<"EOF";
Reply-to:$EmailAddress
From:$EmailAddress

$comments
EOF
close(MAIL);
select(STDOUT);

$url="livonia_rugby_email.cgi";
print "Location: $url\n\n";
exit;
sub GetFormInput {

(*fval) = @_ if @_ ;

local ($buf);
if ($ENV{'REQUEST_METHOD'} eq 'POST') {
read(STDIN,$buf,$ENV{'CONTENT_LENGTH'});
}
else {
$buf=$ENV{'QUERY_STRING'};
}
if ($buf eq "") {
return 0 ;
}
else {
@fval=split(/&/,$buf);
foreach $i (0 .. $#fval){
($name,$val)=split (/=/,$fval[$i],2);
$val=~tr/+/ /;
$val=~ s/%(..)/pack("c",hex($1))/ge;
$name=~tr/+/ /;
$name=~ s/%(..)/pack("c",hex($1))/ge;

if (!defined($field{$name})) {
$field{$name}=$val;
}
else {
$field{$name} .= ",$val";

#if you want multi-selects to goto into an
array change to:
#$field{$name} .= "\0$val";
}

}
}
return 1;
}

A:
To send a mail attachment you have to format your mail to MIME format.
Attachments are encoded into the body of the mail, only the local client
detach the files. Look for the definition of MIME.

I would recommend that you use some Perl module, like Net::SMTP.

Regards,
Peter

*******************
Please take your time and rate me at AllExperts.com
I ask you to do that the way you believe I deserve.
This is a feedback that I get from allexperts but
it does not affect my life in any financial way. This
is just a mental feedback.

In case you think my answer was really good and if you feel
it appropriate do not hesitate to nominate me to volunteer
of the month.

I do this job volunteer in my free time and this is all I get
as compensation.

[ back to toc ]