The Problem - Getting this to run as part of add.cgi when a link is submitted
The Reason - Adding a user's e-mail address to a textfile my newsletter software uses to send my weekly newsletter. The goal is that when a person enters their information and doesn't uncheck the "doThis" checkmark on the add.html template's form (which when checked means they want to subscribe to the newsletter) they are added to address.txt if not already in it as a subscriber. I am absolutely sure that $in{'doThis'} DOES return the text "subscribe". I tested this already. But the fact is no matter where I put &subscribe; or if i take out the "sub subscribe {" and the matching "}" and leave this code at the end of add.cgi it just doesn't add their mail to address.txt nor does it send webmaster@websitegoodies.com any email, meaning to me that this portion of code (below) just isn't happening at all. Any help getting it to work would be appreciated, this is to automate subscriptions to my newsletter through links and other scripts on my site.
I tried changing
to
but this didn't work.
# Define a few important variables
$mailprogram = "/usr/lib/sendmail -t"; # path to sendmail with a modifier
$subscription = "/home/goodies/www/cgi-bin/address.txt"; # name of the file that stores the email list
$greetings = "../address.txt"; # welcome message to send to new subscribers
$sender = "newsletter\@websitegoodies.com"; # notice that all email @ signs are backslashed
$sendername = "WSG Webmaster News";
if ($ENV{"REQUEST_METHOD"} eq 'GET') { $buffer = $ENV{'QUERY_STRING'}; }
else { read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); }
if ($in{'doThis'} eq "subscribe") {
# Now that you have the data, find out what you're telling
# the script to do and let it call the appropriate function
# (subroutine) to perform the task.
unless($in{'email'} =~ /.*\@.*\..*/) {
$validmail = "no";
exit;
}
open(OLDLIST, "$subscription");
@subscribers = <OLDLIST>;
close(OLDLIST);
#Now write over the original subscription list entry by entry
#Compare each entry with that of the new subscriber - if they are
#one and the same, print out a message saying that the email
#address is already on the list, otherwise, write the old entries
#into the file.
#At the end, don't forget to add the new entry to the end of the
#file - AFTER the foreach loop.
open(NEWLIST, ">$subscription");
foreach $recipient(@subscribers) {
chomp($recipient);
if ($recipient eq $in{'Contact Email'}) {
$subscribed = true;
}
else { print NEWLIST "$recipient\n"; }
}
if(!$subscribed) { print NEWLIST "$in{'Contact Email'}\n"; }
close(NEWLIST);
#Now that the email address has been successfully added, send
#a message to the new subscriber confirming the addition:
open (MAIL, "|$mailprogram") | | die "Can't open $mailprogram!\n";
print MAIL "To: webmaster\@websitegoodies.com\n";
print MAIL "From: $in{'Contact Email'} < $in{'Contact Name'} >\n";
print MAIL "Subject: Subscription Confirmed!\n";
print MAIL "Address Added ( $in{'Contact Email'} )";
close(MAIL);
print "Subscribed.";
}
}
Thanks to all who can help
The Reason - Adding a user's e-mail address to a textfile my newsletter software uses to send my weekly newsletter. The goal is that when a person enters their information and doesn't uncheck the "doThis" checkmark on the add.html template's form (which when checked means they want to subscribe to the newsletter) they are added to address.txt if not already in it as a subscriber. I am absolutely sure that $in{'doThis'} DOES return the text "subscribe". I tested this already. But the fact is no matter where I put &subscribe; or if i take out the "sub subscribe {" and the matching "}" and leave this code at the end of add.cgi it just doesn't add their mail to address.txt nor does it send webmaster@websitegoodies.com any email, meaning to me that this portion of code (below) just isn't happening at all. Any help getting it to work would be appreciated, this is to automate subscriptions to my newsletter through links and other scripts on my site.
I tried changing
Code:
else { print NEWLIST "$recipient\n"; }to
Code:
else { print NEWLIST "in{'Contact Email'}\n"; }but this didn't work.
Code:
sub subscribe { # Define a few important variables
$mailprogram = "/usr/lib/sendmail -t"; # path to sendmail with a modifier
$subscription = "/home/goodies/www/cgi-bin/address.txt"; # name of the file that stores the email list
$greetings = "../address.txt"; # welcome message to send to new subscribers
$sender = "newsletter\@websitegoodies.com"; # notice that all email @ signs are backslashed
$sendername = "WSG Webmaster News";
if ($ENV{"REQUEST_METHOD"} eq 'GET') { $buffer = $ENV{'QUERY_STRING'}; }
else { read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); }
if ($in{'doThis'} eq "subscribe") {
# Now that you have the data, find out what you're telling
# the script to do and let it call the appropriate function
# (subroutine) to perform the task.
unless($in{'email'} =~ /.*\@.*\..*/) {
$validmail = "no";
exit;
}
open(OLDLIST, "$subscription");
@subscribers = <OLDLIST>;
close(OLDLIST);
#Now write over the original subscription list entry by entry
#Compare each entry with that of the new subscriber - if they are
#one and the same, print out a message saying that the email
#address is already on the list, otherwise, write the old entries
#into the file.
#At the end, don't forget to add the new entry to the end of the
#file - AFTER the foreach loop.
open(NEWLIST, ">$subscription");
foreach $recipient(@subscribers) {
chomp($recipient);
if ($recipient eq $in{'Contact Email'}) {
$subscribed = true;
}
else { print NEWLIST "$recipient\n"; }
}
if(!$subscribed) { print NEWLIST "$in{'Contact Email'}\n"; }
close(NEWLIST);
#Now that the email address has been successfully added, send
#a message to the new subscriber confirming the addition:
open (MAIL, "|$mailprogram") | | die "Can't open $mailprogram!\n";
print MAIL "To: webmaster\@websitegoodies.com\n";
print MAIL "From: $in{'Contact Email'} < $in{'Contact Name'} >\n";
print MAIL "Subject: Subscription Confirmed!\n";
print MAIL "Address Added ( $in{'Contact Email'} )";
close(MAIL);
print "Subscribed.";
}
}
Thanks to all who can help