Hi...
This is my first try for writing my OWN tutorial.
So, I'll write a PERL script for a mailing list, without SQL or any other database.
Code:
#!/usr/bin/perl -w
# put above path to your perl interpreter
$dbDir = '.';
# directory where you want to save data
$dbFile = 'maillist.dat';
# put above file where you want to save data...
$mailProgie = '/usr/sbin/sendmail';
# put above path to your sendmail progie
$adminEmail = 'whatever@addy.com';
# put above administrator's mail
$adminName = 'Whatever Name';
# put above administrator's name
use CGI;
$req = new CGI;
$action = $req->param("action");
sub sendEmail {
$getSubject = $req->param("subject");
$getMessage = $req->param("message");
open(FILE,"<$dbDir/$dbFile");
@dataFile = split(/¦¦/,<FILE>);
close(FILE);
foreach $dataFile (@dataFile) {
my @tempData = split(/¦/,$dataFile);
open MAIL, "|$mailProgie -t -i" || die "open: $!";
print MAIL "To: $tempData[0]($tempData[1])\n";
print MAIL "From: $adminEmail($adminName)\n";
print MAIL "Subject: $getSubject\n";
print MAIL "Content-type: text/html\n\n";
# print MAIL "Content-type: text/plain\n\n"; if you will use text/plain
print MAIL "$getMessage\n";
close MAIL;
}
print "&ret=true&";
}
I'll assume that all who read this tutorial know where to put this .pl file and how to make a form to send data to it.
So, that's it for my tutorial.
Please tell me on how i can improve it or if it has been posted before.
Thanks. :D
September 17th, 2002, 09:47 PM
a_420_hacker_24
Good tut on perl.I like it when I see more people posting in perl.