View Full Version : email when page changes cgi script
rebelo
11-14-2003, 09:57 AM
Hi.
Does anyone know whre I can get an "email when a page changes" cgi script.
There are several remote hosted services alike but I would like to keep it in my server.
YUPAPA
11-15-2003, 12:39 AM
Are you looking for a formmail script which can let your visitors send email to you on your web site and redirect them page to a page? :)
rebelo
11-15-2003, 09:59 AM
No.
Looking for a script that some one submits his own email in a certain webpage and when I change this page he will get an email informing that page was updated.
There are several remote hosted services to do this but i need to keep it in my server. :confused:
dswimboy
11-25-2003, 06:03 PM
You will need two seperate perl scripts.
One should handle adding the address to an outside text file.
when the user submits his email address, the first script should check to make sure it isn't already in the list. if it isn't in the list, it should add it. i would put each address on a new line.
#!/usr/bin/perl
open("< list.txt", LIST);
$LIST = <LIST>;
close LIST;
unless ($LIST =~ $address) {
open (">> list.txt", LIST);
print LIST "\n$address";
close LIST;
}
the second script should be run everytime you update the page.
the script should open the text file, and foreach line should send an email to the address, which is the value of the line.
#!/usr/bin/perl
open("< list.txt", LIST);
@LIST = <LIST>;
close LIST;
foreach $line (@LIST) {
// open mail pipe
// print message to mail pipe
}
Jeff Mott
11-27-2003, 03:49 AM
dswimboy has the right idea, but it looks like he was thinking in a different programming language when writing the code. Maybe this# add e-mail address to list
use strict;
use warnings FATAL => 'all';
use CGI;
use Fcntl qw[:DEFAULT :flock :seek];
my $cgi = CGI->new();
sysopen LIST, 'list.txt', O_RDWR|O_CREAT or die $!;
flock LIST, LOCK_EX or die $!;
while (<LIST>) {
chomp;
if (lc $_ eq lc $cgi->param('email')) {
print $cgi->header(), $cgi->start_html(), $cgi->p('The e-mail address is already in our list.'), $cgi->end_html();
exit;
}
}
seek LIST, 0, SEEK_END or die $!;
print LIST $cgi->param('email'), "\n" or die $!;
close LIST or die $!;
print $cgi->header(), $cgi->start_html(), $cgi->p('The e-mail address has been added to our list.'), $cgi->end_html();# read list; send e-mail
use strict;
use warnings FATAL => 'all';
use CGI;
use Fcntl qw[:flock];
my $cgi = CGI->new();
open LIST, 'list.txt' or die $!;
flock LIST, LOCK_SH or die $!;
while (<LIST>) {
chomp;
# current e-mail: $_
# send mail here
}
close LIST or die $!;
print $cgi->header(), $cgi->start_html(), $cgi->p('Mail sent.'), $cgi->end_html();
dswimboy
11-27-2003, 05:11 AM
what is wrong with my code? the only problem i see is using // instead of # to comment.
Jeff Mott
11-27-2003, 05:21 AM
You also have the arguments for open in the wrong order.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.