Results 1 to 8 of 8

Thread: cgi perl email/announcement list

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 1999
    Location
    London, England
    Posts
    213

    cgi perl email/announcement list

    I want to set up an announcement email list for my web site which will allow users to enter their e-mails and populate the list so that I can send them all an email and update them with what's going on.

    Can someone show me how I can do this in perl cgi ?

  2. #2
    scoutt
    Guest
    ummm for somebody that doesn't know hardly anything about cgi, aren't you asking a lot ???-- just kiding . the best thing I can say is go HERE and check these out. some are free but some cost money.

  3. #3
    Fanatic Member gwdash's Avatar
    Join Date
    Aug 2000
    Location
    Minnesota
    Posts
    666
    how is this list being stored (DBMS, Unix DBM, flatfile, etc.)?

    if it's a flat file, then it can be done quickly, same whith DBM, using a DBMS (MySQL, mSQL, Oracle, MS SQL, etc.) requires a bit more work, but is possible. (you need the perl DBI module)

    Handling the form submition can be done with the CGI module (i've had trouble with it, but it's default with perl, i use the CGI::Minimal module from CPAN)

    as for sending email, what OS are you on, with Unix/Linux it's a snap. WinNT requires CDO for NTS, but can be done (using ASP instead of perl, but you said perl, so thats not an option).

    i need a bit more information before i can give you some code/
    GWDASH
    [b]VB6, Perl, ASP, HTML, JavaScript, VBScript, SQL, C, C++, Linux , Java, PHP, MySQL, XML[b]

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Sep 1999
    Location
    London, England
    Posts
    213
    Firstly, the emails are stored in a mySQL database on a linux platform. This is populated by using an asp script. After registration I use a mail.cgi script to confirm registration to the
    user. (my webserver doesn't support CDO)

    What would be the best option:

    1. write/append all the emails at registration to a flat file from my asp script and then use a perl script to send an e-mail to all the users on that list,

    or

    2. should I open a connection to the mySQL DB, read all the emails from a table and send an email to every body in that list.

    Can you please advise.

    Is there any other info you require ?

    Thanks.

  5. #5
    Fanatic Member gwdash's Avatar
    Join Date
    Aug 2000
    Location
    Minnesota
    Posts
    666
    i believe the second option makes more sence, this is similar to what my company is doing now. Using perl DBI, you can connect to MySQL, retrieve the emails, validate them if you want (using a module on CPAN), and then send emails. i assume your on a unix/linux machine, so you need to find the path to sendmail,

    just type:

    which sendmail

    at your terminal, or if you don't have a terminal, ask your system administrator

    then use a perl script to shell out sendmail, and email away.

    i'll post some code when i get back later today.
    GWDASH
    [b]VB6, Perl, ASP, HTML, JavaScript, VBScript, SQL, C, C++, Linux , Java, PHP, MySQL, XML[b]

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Sep 1999
    Location
    London, England
    Posts
    213
    I have found out the folowing info:

    1. path to perl

    #!/usr/bin/perl

    2. mail program
    $mail_prog = '/usr/sbin/sendmail' ;

    I appreciate your help. Thanks.

  7. #7
    Fanatic Member gwdash's Avatar
    Join Date
    Aug 2000
    Location
    Minnesota
    Posts
    666
    ok, try something like this then:
    Code:
    #!/usr/bin/perl
    #use DBI module, make sure both DBI and DBD:MySQL are installed
    
    use DBI;
    
    #path to mail program
    $mail_prog = '/usr/sbin/sendmail' ; 
    
    #message to send
    $message = "";
    
    #DB connect information
    $database="";
    $hostname="";
    $user="";
    $password="";
    $driver = "mysql";
    $dsn = "DBI:$driver:database=$database;host=$hostname;";
    
    #connect
    my $dbh = DBI->connect($dsn, $user, $password);
    
    my $sth = $dbh->prepare("SELECT email FROM Table_With_Emails");
    
    $sth->execute();
    
    #populate recipients
    while(($email) = $sth->fetch_rowarray){
       $recipients .= $email;
       $recipients .= ",";
    }
    
    #remove trailing comma, not efficient, but quick and dirty
    $recipients =~ s/,$//;
    
    open(SENDMAIL, "| $mail_prog -t");
    select(SENDMAIL);
    print "To: $recipients\n";
    print "$message";
    #print "\n.\n"; #not sure if nessecary, try both ways
    select(STDOUT);
    close(SENDMAIL);
    haven't tested, i'm not infront of a unix box now.
    GWDASH
    [b]VB6, Perl, ASP, HTML, JavaScript, VBScript, SQL, C, C++, Linux , Java, PHP, MySQL, XML[b]

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Sep 1999
    Location
    London, England
    Posts
    213
    Thanks.

    I've understood the code and I know what to do to get it up and running, however, I'm afraid I don't know anything about the DBI and DBD modules. Where do I get these from and how and where do I upload them to ?

Posting Permissions

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



Click Here to Expand Forum to Full Width