Gossamer Forum
Home : General : Perl Programming :

Sending file by email blues :(

Quote Reply
Sending file by email blues :(
Please can someone tell me why this won't work! I thought at first it must be the location to sendmail, but that didnt work (tried all three different locations possibilities). I then added an error sub to see if the email actually was being sent, but that didn't return anything, so now I am officially stumped! Any ideas you guys? I have never learned how to program the encode stuff, so all of this is new to me Frown

Well, here is the code;

Code:
#!/usr/bin/perl

### User variables - you may change things in this section as indicated ###

# Change this to the correct path to Sendmail for your system #
$mailprog="/usr/lib/sendmail";

# Change this to the LITERAL PATH to the files you wish to mail. Do not forget the ending / #
$filelocation="/home/wwwtempl/public_html/templates/purchase/download/";

# Change this to the email address you want mails to be sent FROM and leave \ behind the @ sign#
$adminmail="webmaster\@wwwtemplates.com";

# Change this to the name you want mails to be sent FROM #
$adminname="Webmaster";

# Change this to reflect the subject line you require for your mails #
$subjectline="Your Template from WWWTemplates.com";

# Change this to show the message you want to include (i.e. the body of the email). #
# A new line is entered by using \n e.g. Hi there\n\nThank-you for your interest in blah blah #
# Note that "Dear Name\n\n" has been inserted for you automatically, Name being the name submitted #

# Change this to the URL of the screen you want to display after the user has submitted the form #
#(i.e. a confirmation screen)#
$returnscreen="http://wwwtemplates.com/templates/purchase/safe/confirmed.cgi?do=sent";

# DO NOT alter anything from here on #

read (STDIN,$temp,$ENV{'CONTENT_LENGTH'});
@pairs=split(/&/,$temp);
foreach $item(@pairs)
{
($key,$content)=split (/=/,$item);
$content=~tr /+/ /;
$content=~s /%(..)/pack("c",hex($1))/ge;
$fields{$key}=$content;
}

require ("mimetypes.pl");

&sendproduct;

$message = qw~First of all, let me congratulate you on your purchase from our quality selection of templates. We hope you enjoy using your purchase, and it saves you a lot of money from time you would have otherwise spent trying to do something like this! Please find attached a copy of the template you just purchased. ~;

sub sendproduct
{

$file=$filelocation.$fields{'attachment'};
($ext) = $file =~ m,\.([^\.]*)$,;
$ext =~ tr,a-z,A-Z,;
$fext=&mimetype($ext);


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

open MAIL, "| $mailprog -t" || die &error('$!');
print MAIL "To: $fields{'email'}\n";
print MAIL "From: $adminmail\n";
print MAIL "MIME-Version: 1.0\n";
print MAIL "Subject: $subjectline\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 "$message";
print MAIL "\n";
print MAIL "--------------$boundary\n";
print MAIL "Content-Type: $fext; name=\"$fields{'attachment'}\"\n";
print MAIL "Content-Transfer-Encoding: base64\n";
print MAIL "Content-Disposition: inline; filename=\"$fields{'attachment'}\"\n\n";

my $buf;
$/=0;
open INPUT, "$file";
binmode INPUT if ($^O eq 'NT' or $^O eq 'MSWin32');
while(read(INPUT, $buf, 60*57))
{
print MAIL &encode_base64($buf);
}
close INPUT;

print MAIL "\n--------------$boundary--\n";
print MAIL "\n";
close MAIL;
print "Location: $returnscreen\n\n";
exit();
}


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;
}

sub error
{

$error = shift;

print "Content-type: text/html \n\n";
print "$error";

}
Thanks to anyone that can help!

Andy

webmaster@ace-installer.com
http://www.ace-installer.com
Subject Author Views Date
Thread Sending file by email blues :( Andy 13092 Aug 27, 2001, 4:22 AM
Thread Re: Sending file by email blues :(
Paul 12900 Aug 27, 2001, 4:35 AM
Thread Re: Sending file by email blues :(
Andy 12924 Aug 27, 2001, 5:30 AM
Post Re: Sending file by email blues :(
Paul 12884 Aug 27, 2001, 5:35 AM
Thread Re: Sending file by email blues :(
Paul 12905 Aug 27, 2001, 5:36 AM
Post Re: Sending file by email blues :(
Andy 12894 Aug 27, 2001, 5:40 AM
Thread Re: Sending file by email blues :(
Alex 12882 Aug 27, 2001, 9:54 AM
Post Re: Sending file by email blues :(
Andy 12866 Aug 27, 2001, 12:35 PM
Thread Re: [Andy] Sending file by email blues :(
delicia 10993 Feb 3, 2020, 8:01 AM
Thread Re: [delicia] Sending file by email blues :(
Andy 10988 Feb 3, 2020, 10:21 AM
Thread Re: [Andy] Sending file by email blues :(
delicia 10987 Feb 3, 2020, 11:44 AM
Thread Re: [delicia] Sending file by email blues :(
Andy 10974 Feb 4, 2020, 12:09 AM
Thread Re: [Andy] Sending file by email blues :(
delicia 10969 Feb 4, 2020, 6:51 AM
Thread Re: [delicia] Sending file by email blues :(
Andy 10972 Feb 4, 2020, 6:53 AM
Thread Re: [Andy] Sending file by email blues :(
delicia 10497 Mar 15, 2020, 7:36 AM
Post Re: [delicia] Sending file by email blues :(
Andy 10489 Mar 16, 2020, 12:16 AM
Thread Re: [delicia] Sending file by email blues :(
Andy 10490 Mar 16, 2020, 12:18 AM
Thread Re: [Andy] Sending file by email blues :(
delicia 10478 Mar 16, 2020, 1:32 PM
Thread Re: [delicia] Sending file by email blues :(
Andy 10471 Mar 17, 2020, 12:14 AM
Thread Re: [Andy] Sending file by email blues :(
delicia 10409 Mar 18, 2020, 4:54 PM
Thread Re: [delicia] Sending file by email blues :(
Andy 10401 Mar 18, 2020, 11:49 PM
Thread Re: [Andy] Sending file by email blues :(
delicia 10399 Mar 19, 2020, 2:40 AM
Thread Re: [delicia] Sending file by email blues :(
Andy 10392 Mar 19, 2020, 4:03 AM
Thread Re: [Andy] Sending file by email blues :(
delicia 10388 Mar 19, 2020, 5:29 AM
Thread Re: [delicia] Sending file by email blues :(
Andy 10382 Mar 19, 2020, 5:32 AM
Thread Re: [Andy] Sending file by email blues :(
delicia 7108 Mar 19, 2020, 5:38 AM
Thread Re: [delicia] Sending file by email blues :(
Andy 7106 Mar 19, 2020, 5:46 AM
Thread Re: [Andy] Sending file by email blues :(
delicia 7106 Mar 19, 2020, 5:53 AM
Thread Re: [delicia] Sending file by email blues :(
Andy 7104 Mar 19, 2020, 5:57 AM
Thread Re: [Andy] Sending file by email blues :(
delicia 7107 Mar 19, 2020, 6:04 AM
Thread Re: [delicia] Sending file by email blues :(
Andy 7102 Mar 19, 2020, 6:08 AM
Thread Re: [Andy] Sending file by email blues :(
delicia 7099 Mar 19, 2020, 6:20 AM
Thread Re: [delicia] Sending file by email blues :(
delicia 7095 Mar 19, 2020, 8:24 AM
Thread Re: [delicia] Sending file by email blues :(
Andy 7097 Mar 19, 2020, 8:45 AM
Thread Re: [Andy] Sending file by email blues :(
delicia 7093 Mar 19, 2020, 10:21 AM
Thread Re: [delicia] Sending file by email blues :(
Andy 7084 Mar 20, 2020, 12:06 AM
Thread Re: [Andy] Sending file by email blues :(
delicia 7075 Mar 20, 2020, 3:23 AM
Thread Re: [delicia] Sending file by email blues :(
Andy 7075 Mar 20, 2020, 3:38 AM
Thread Re: [Andy] Sending file by email blues :(
delicia 7080 Mar 20, 2020, 3:43 AM
Thread Re: [delicia] Sending file by email blues :(
Andy 7073 Mar 20, 2020, 3:45 AM
Thread Re: [Andy] Sending file by email blues :(
delicia 7070 Mar 20, 2020, 3:50 AM
Thread Re: [delicia] Sending file by email blues :(
Andy 7071 Mar 20, 2020, 4:10 AM
Thread Re: [Andy] Sending file by email blues :(
delicia 7077 Mar 20, 2020, 4:29 AM
Post Re: [delicia] Sending file by email blues :(
Andy 7067 Mar 20, 2020, 4:34 AM
Post Re: [delicia] Sending file by email blues :(
Andy 7077 Mar 20, 2020, 2:01 AM