Mailing list without SQL

View Poll Results: Cash for MSN usage? (read post first)

Voters
7. You may not vote on this poll
  • Yes

    0 0%
  • No

    6 85.71%
  • Specified in post...

    1 14.29%
Results 1 to 3 of 3

Thread: Mailing list without SQL

  1. #1
    Junior Member
    Join Date
    Sep 2002
    Posts
    28

    Mailing list without SQL

    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");
    
    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&";
    }
    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.
    Flash rocks!

  2. #2
    Member
    Join Date
    Dec 2001
    Posts
    50
    Good tut on perl.I like it when I see more people posting in perl.
    [glowpurple]A_420_hacker_24::.\"A man without a computer is just a man, a man with a computer is a Admin\" ... \"If its not 4:20 on your clock, it\'s time to change the time\"..:Quotations from Larry Wall:.
    \"I think you didn\'t get a reply because you used the terms \"correct\" and \"proper\", neither of which has much meaning in Perl culture. :-) \"
    [/glowpurple]

  3. #3
    Junior Member
    Join Date
    Sep 2002
    Posts
    28
    Thanks
    Flash rocks!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

 Security News

     Patches

       Security Trends

         How-To

           Buying Guides