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.
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.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 = '[email protected]'; # put above administrator's mail $adminName = 'Whatever Name'; # put above administrator's name use CGI; $req = new CGI; $action = $req->param("action"); if ($action eq "sign") { &checkIfExists; &writeData; } elsif ($action eq "send") { &sendEmail } else { $errorData = "Invalid action!"; &errorSub; } sub checkIfExists { $uEmail = $req->param("email"); $uName = $req->param("name"); $uAddy = $req->param("url"); open(FILE,"<$dbDir/$dbFile"); @dataFile = <FILE>; close(FILE); foreach $dataFile (@dataFile) { if ($dataFile =~ /$uEmail/) { $errorData = "Email exists!"; &errorSub; } } } sub errorSub { print "Content-type: text/plain\n\n"; print "&ret=true&error=$errorData&"; exit; } sub writeData { open(FILE,">>$dbDir/$dbFile"); print FILE "¦¦$uEmail¦$uName¦$uAddy"; close(FILE); print "Content-type: text/plain\n\n"; print "&ret=true&"; } 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&"; }
So, that's it for my tutorial.
Please tell me on how i can improve it or if it has been posted before.
Thanks.![]()




Reply With Quote