#!/usr/local/bin/perl -w #EDIT THE ABOVE LINE TO POINT TO PERL ON YOUR SYSTEM # #File: MailList_basic.pl - Version 3.00 # #Get the current working directory to add to the list of places to search #for the files specified by the "require" statements. $ENV{"PATH_TRANSLATED"} =~ s/\w+\..{1,}$//; push (@INC,$ENV{"PATH_TRANSLATED"}); # # This program was written to support basic mailing-list functionality #without being dependent on an actual email alias for the mailing list. This #increases the portability while also significantly reducing the possibilitiy #of spammers spamming members. # # This particular file will do one of the following depending on the #parameters passed to it: # 0 - Print subscribe form. This is done by default. # 1 - Mail confirmation subscribe email to the user requesting to sign up. # 2 - Subscribe to the list if the user clicks on the link within their confirmation email. # #REQUIREMENTS: # 1) Perl Version >= 5.003 OR ActiveState Active Perl Version >= 5.6.1 # 2) You must have a mail server running on the machine this script # is installed on. # 3) The CPAN MIME::Base64 Perl Module must be installed (comes with ActivePerl) # 4) The CPAN Net::SMTP Perl Module must be installed (comes with ActivePerl) # 5) The "lozcgi.pl" perl module. It's included as part of the archive and # available from http://www.davelozinski.com/scripts/ # #INSTALLATION: # 1) Set the path to the "require" statement below if you do not keep all your files # in the same directory. # 2) Set the values located in the "MailListConfigs_basic.pl" # file. ALL VALUES SHOULD BE ENCLOSED IN QUOTES. # 3) Complete the "installation" section of the file "MailListAdmin_basic.pl". # #RUNNING: # 1) The link to print the "Subscribe" form to your users is: # http://www.yourdomain.com/cgi-bin/MailList_basic.pl # #ADDITIONAL FEATURES AVAILABLE IN THE ADVANCED VERSION # 1) Providing the Unsubscribe form to allow users to automatically unsubscribe # from the list. # 2) Mail confirmation unsubscribe email to the user requesting to be removed. # 3) Unsubscribing the user from the list if they click on the link within their confirmation email. # 4) Support for multiple lists # #More details can be found at http://www.davelozinski.com/scripts/ # #WHERE/HOW TO PURCHASE THE ADVANCED VERSION # http://www.davelozinski.com/scripts # #LICENSE: # You are free to further develop/modify the source code to fit your #needs, but you MAY NOT resell and/or redistribute the source code in any #way, manner, fashion, or form without my hand-written consent! # # This license grants the purchaser of this archive the permission to #have an unlimited number of users use this script at any time. #Likewise, the purchaser may have any number of copies of this script as long #as the media that this program resides on or run from is owned by the purchaser. #If not, more licenses MUST be purchased. # #Examples: # 1) If you have your own webserver hosting your various customers, you only need once license #to run the code on your webserver to provide the email functionality to your clients hosted on your server. # 2) If you are designing websites for 3 individual clients, each of which wants the email functionality, #and each of which will be hosting their websites and emailer on their own server, #then you need to purchase 3 licenses. # #If you modify the source code in anyway for your own purposes, the #original header-comments must remain intact. # #REVISION HISTORY: # 3.00 07/31/04 Updated with advanced script. # 2.10 07/04/04 Updated to keep up with "advanced" version. # 2.00 04/12/03 Functionality improved. # 1.01 06/18/02 Corrected a Mail formatting issue # 1.00 03/01/02 Original Version # #CONTACT INFORMATION: # http://www.davelozinski.com/cgi-bin/email_lozinski.pl # use MIME::Base64; use Net::SMTP; use Fcntl ':flock'; # import LOCK_* constants require("lozcgi.pl"); require("MailListConfigs_basic.pl"); ################################ #NOTHING BELOW THIS LINE SHOULD NEED TO BE CONFIGURED ################################ &GetData; $a = defined($in{"a"}) ? $in{"a"} : 9; $e = defined($in{"e"}) ? $in{"e"} : ""; $AnError = 0; $ErrorMessage = ""; $Title = ""; $Title_String = ""; $Admin_Email = ""; $Email_Admin_With_List_Update = 0; $Mail_Subscribe_Thank_You_Letter = 0; $Send_HTML_Format = 0; $msg_body = ""; $subject = ""; $localtime = time + (60 * 60); $datestring = ""; $mailheaders = ""; $smtp = ""; if ($a =~ /\d/) { #0 - Print subscribe form if ($a>2 || $a<0) { #1 - Mail confirmation subscribe email $a = 0; #2 - Subscribe to list } } else { $a = 0; } $Title_String = "Mailing List "; if (($a==1 || $a==2) && ($e eq "")) { $AnError = 1; $ErrorMessage = "

You need to provide your email address.

\n"; } elsif (($a==1) && !&IsValidEmailAddress($e)) { $AnError = 1; $ErrorMessage = "

You need to provide a valid email address.

\n"; } elsif (($a==2) && !&IsValidEmailAddress(decode_base64($e))) { $AnError = 1; $ErrorMessage = "

You need to provide a valid email address.

\n"; } if (!$AnError) { $Title = $C_TITLE; $Admin_Email = $C_ADMIN_EMAIL; $Email_Admin_With_List_Update = $C_EMAIL_ADMIN_WITH_LIST_UPDATE; $Mail_Subscribe_Thank_You_Letter = $C_MAIL_SUBSCRIBE_THANK_YOU_LETTER; $Send_HTML_Format = $C_SEND_HTML_FORMAT; $Mail_List_Data_File = $C_MAIL_LIST_DATA_FILE; $Title_String .= "for: \"" . $Title . "\""; } &StartHTML($Title_String,"","","","","","",1); if ($AnError) { print ($ErrorMessage); } else { if ($a == 1) { #Mail the confirmation subscribe or unsubscribe email $mailheaders = "From: " . $Admin_Email . "\n"; $mailheaders .= "Reply-To: " . $Admin_Email . "\n"; $mailheaders .= "To: " . $e . "\n"; $mailheaders .= "Subject: Confirmation Email: " . $Title . "\n"; $mailheaders .= "MIME-version: 1.0\n"; $mailheaders .= "Content-Type: text/html; charset=iso-8859-1;\n"; $mailheaders .= "Content-Transfer-Encoding: 7bit\n"; $msg_body = "" . $Title . "\n"; $msg_body .= "You are receiving this email because your email address was submitted to "; $msg_body .= "subscribe to: "; $msg_body .= "\n\"" . $Title . "\".\n\n

To confirm, click on the link below. "; $msg_body .= "If you cannot, copy and paste the URL into your browser. Thank you!

\n\n"; $msg_body .= "" . $SCRIPT_URL . "?l=" . $l . "&a=2&e=" . URLEncode(encode_base64($e)); $msg_body .= "

\n\n\n"; if ($smtp = Net::SMTP->new("localhost")) { $smtp->mail("$Admin_Email"); $smtp->to("$e"); $smtp->data(); $smtp->datasend("$mailheaders"); $smtp->datasend("\n"); $smtp->datasend("$msg_body\n"); $smtp->dataend(); $smtp->quit(); print ("

Thank you! A confirmation email has been sent to \"" . $e . "\".

\n"); print ("You need to click on the URL (or copy and paste it into your browser) to confirm your selection.

\n"); } else { print ("

An error occurred and a confirmation email could not be sent to \"" . $e . "\".

\n"); print ("If the problem persists, please contact " . $Admin_Email . ". Thank you!

\n"); } } elsif ($a == 2) { # Subscribe to the list my $found = 0; if ( open (FP,$C_MAIL_LIST_DATA_FILE{$l}) ) { while ($line = ) { #See if they already subscribed to the list if (!$found) { ($email,$date) = split(/\|/,$line); if ($email eq decode_base64($e)) { $found = 1; last; } } } close(FP); if (!$found) { #They haven't already subscribed $datestring = sprintf("%4.4d",((localtime($localtime))[5]+1900)) . "-"; $datestring .= sprintf("%2.2d",((localtime($localtime))[4] + 1)) . "-"; $datestring .= sprintf("%2.2d",((localtime($localtime))[3])); if ( open (FP, ">>" . $C_MAIL_LIST_DATA_FILE{$l}) ) { flock (FP,$LOCK_EX); seek (FP,0,2); print FP (decode_base64($e) . "|" . $datestring . "\n"); flock (FP,$LOCK_UN); close(FP); if ($Email_Admin_With_List_Update) { &EmailAdmin($datestring); } print ("

Thank you! You are now subscribed to: " . $Title . "

\n"); if ($Mail_Subscribe_Thank_You_Letter) { $mailheaders = "From: " . $Admin_Email . "\n"; $mailheaders .= "Reply-to: " . $Admin_Email . "\n"; $mailheaders .= "To: " . decode_base64($e) . "\n"; $mailheaders .= "Subject: Thank you for subscribing to: " . $Title . "\n"; $msg_body = "Thank you for subscribing to " . $Title . "!\n\n"; $e = decode_base64($e); if ($smtp = Net::SMTP->new("localhost")) { $smtp->mail("$Admin_Email"); $smtp->to("$e"); $smtp->data(); $smtp->datasend("$mailheaders"); $smtp->datasend("\n"); $smtp->datasend("$msg_body\n"); $smtp->dataend(); $smtp->quit(); } else { print ("

An error occurred and a confirmation email could not be sent to \"" . $e . "\".

\n"); print ("If the problem persists, please contact " . $Admin_Email . ". Thank you!

\n"); } } } else { #Couldn't open the list member datafile for saving print ("

An error occurred, and your confirmation could not be saved. Please try again. \n"); print ("If you continue to experience problems, please email " . $Admin_Email . ". Thank you!

\n"); } } else { print("

You have already subscribed to \"" . $Title . "\".

\n"); } } } else { #Print the subscribe form by default print <<__END_OF_HTML_CODE__;

$Title : Subscribe

Enter your email address below. A confirmation email will be sent to your email address.



__END_OF_HTML_CODE__ } } &FinishHTML(1); ################################ sub IsValidEmailAddress { my ($theAddress) = @_; $valid = $theAddress =~ /^(([\w\-\_])+(\.)*)+\@([\w\-\_]+\.)+[A-Za-z]{2,}$/i; } ### IsValidEmailAddress ################################ ################################ sub URLEncode { my ($theAddress) = @_; $theAddress =~ s/([^a-zA-Z0-9_\-.])/uc sprintf("%%%02x",ord($1))/eg; return $theAddress; } ### IsValidEmailAddress ################################ ################################ #sub EmailAdmin # Sends an email to the address specified by $C_ADMIN_EMAIL #everytime someone confirms to subscribe or unsubscribe #from the mailing list. This function is only called if #$C_EMAIL_ADMIN_WITH_LIST_UPDATE is set to 1 (yes). ################################ sub EmailAdmin { my ($lt) = @_; $e = decode_base64($e); $mailheaders = "From: " . $Admin_Email . "\nReply-to: " . $Admin_Email . "\n"; $mailheaders .= "To: " . $Admin_Email . "\n"; $mailheaders .= "Subject: Mail List Update for: " . $Title . "\n"; $msg_body = "\"" . $e . "\""; $msg_body .= " subscribed to \"" . $Title . "\" on: "; $msg_body .= $lt . "\n"; if ($smtp = Net::SMTP->new("localhost")) { $smtp->mail("$Admin_Email"); $smtp->to("$Admin_Email"); $smtp->data(); $smtp->datasend("$mailheaders"); $smtp->datasend("\n"); $smtp->datasend("$msg_body\n"); $smtp->dataend(); $smtp->quit(); } else { print ("

An error occurred. Please notify " . $Admin_Email . ". Thank you!

\n"); } $e = encode_base64($e); } ################################