Download and Log Script - oh boy

They have: 29 posts

Joined: May 1999

Ok, this past week I just started understanding Perl a whole lot better so I wrote a "Tell-A-Friend" script which works with flying colors. So next I wanted to make a script that would keep a log of everyone who downloaded it, so when I make upgrades I can email everyone about it.

So this is what I did. I made a form which would send the persons email address to the script. Everything right so far. In the script I made it so it would take the persons email address, add it to the end of the log files, and forward the person to the "zip" file so they can download it. I thought I had everything right, but when I sent my email address through the script I get a 500.

So below is the script, if any of you could help me out I would appreciate it. This is one of my first scripts, so it's probably pretty sloppy.

#!/usr/bin/perl

$mailprogram = "/usr/sbin/sendmail";
$scriptname = "Grab-A-Friend 1.1";
$myemail = '[email protected]';
$scriptlog = "/home/webmasters-pub/www/cgi-bin/dl/friend/log.txt";
$scriptdl = "http://www.webmasters-pub.com/scripts/cgi/friend/1.1/friend1-1.zip";
$scriptmain = "http://www.webmasters-pub.com/scripts/cgi/friend/1.1/";
$header = "/home/webmasters-pub/www/cgi-bin/header.txt";
$footer = "/home/webmasters-pub/www/cgi-bin/footer.txt";

read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$FORM{$name} = $value;
}

### change this yet
if ($FORM{'email'}) {
unless ($FORM{'email'} =~ /\w+@\w+.\w+/) {
print "Content-type:text/html\n\n";
&header;
print <<EOL;
The email address you specified for yourself is incorrect email address format. Could you please go back and enter your correct email to download <a href=\"$scriptmain\">$scriptname</a>.<p>

Thank you.

EOL
&footer;
exit;
}
}
###

if ($FORM{'subject'} eq "friend"){&friend;}
else {&badsubject;}

sub friend{

print "Location: $scriptdl\n\n";
###

open (SCRIPTLOG, ">>$scriptlog");
print SCRIPTLOG "$FORM{'email'}\n";

close(SCRIPTLOG);
}

sub badsubject{

}

#----- Begin Templates -----
sub header{

open (HEADER, "$header");
while (<HEADER>) {
print $_;
}
close (HEADER);
}

sub footer {

open (FOOTER, "$footer");
while (<FOOTER>) {
print $_;
}
close (FOOTER);
}

#----- End Templates -----

#----- Begin Email -----

open (MAIL,"¦$mailprogram -t");
print MAIL "To: $FORM{'email'}\n";
print MAIL "From: $myemail\n";
print MAIL "Subject: Thanks for downloading $scriptname\n\n";

print MAIL "Hello $FORM{'email'}!\n";
print MAIL "\n";
print MAIL "This is Ryan Kuhle, co-owner of Webmasters-Pub. I just wanted\n";
print MAIL "to thank you for downloading $scriptname. If you have any comments\n";
print MAIL "or ideas for the script, just let me know at $myemail\n";
print MAIL "\n";
print MAIL "Thanks again!\n";
print MAIL "Ryan Kuhle webmaster\@webmasters-pub.com\n";
print MAIL "Webmasters-Pub: A Webmasters Guide to Success\n";
print MAIL "http://www.webmasters-pub.com\n";
print MAIL "\n";
print MAIL "Make money with \"dead space\" on your website!\n";
print MAIL "http://www.ubrande.com/reseller.php3?1028\n";

close MAIL;

#----- End Email -----

----------
Webmasters-Pub: A Webmasters Guide to Success
http://www.webmasters-pub.com

They have: 29 posts

Joined: May 1999

Never mind folks, I got it working perfect Smiling

----------
Webmasters-Pub: A Webmasters Guide to Success
http://www.webmasters-pub.com

They have: 2,390 posts

Joined: Nov 1998

Glad I could help, anytime Smiling LOL
JP

----------
The Webmaster Forums are part of the Web Currents Network.
The Next Step in Website Development - http://www.what-next.com

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.