dumbadam has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/local/bin/perl use CGI; $q = new CGI; $thefile = "email.txt"; $my_email = "webmaster\@itsmeagain.com"; $email_entered = $q->param('email'); #check for email valid $FORM = $q->param('email') . ","; if ($q->param('email')) { unless ($FORM =~ /\w+@\w+.\w+/) { print $q->header(-type=>'text/html', accept=>'*/*'); print $q->start_html(-title=>'Bad Email'); #print "Content-type: text/html\n\n"; print "<html><head><title>Bad E-mail</title></head>\n" +; print "<body><h1>Bad E-mail</h1><br>The e-mail address + that you've\n"; print "entered,<b><font color='red' size='+3'> $FORM</ +font></b> is invalid. Please click back and\n"; print "try again.\n"; print $q->end_html; exit; } #chk for cookie $JSCRIPT=<<END; function go(){ if (document.referer){ window.parent.location=document.referer; } else{ document.location= "http://www.mysite.com/index2.htm"; } } setTimeout("go()", 5000); END $chkcookie = $q->cookie( "email" ); if ($chkcookie eq $email_entered){ print $q->header(-type=>'text/html', accept=>'*/*'); print $q->start_html(-title=>'Already Entered This Email', script=>$JS +CRIPT); print "<h1><b>You just entered this email address! </h1>---<font size= ++1></b>Click back to continue or wait and I'll send you!"; print $q->end_html; } else { &filewritee; } } else { print $q->header(-type=>'text/html', accept=>'*/*'); print $q->start_html(-title=>'Nothing Entered'); print "<h1>Nothing Entered.</h1><br><br>\n"; print "You didn't enter anything, Pls go back and enter a valid email +address"; print $q->end_html; } sub filewritee{ open (EMAILADDRESS, ">> $thefile") or die "Can't open file: $!"; flock EMAILADDRESS, 2; print EMAILADDRESS $FORM; close EMAILADDRESS; &sendmail; } sub sendmail{ open (MAIL, "| /usr/vde/bin/sendmail -t") or die "couldnt open sendmail: $!"; print MAIL <<EO; To: $email_entered From: $my_email Subject: Weekly mail from me EO open (FILE, "< weekly.htm") or die "Cannot open file: $!"; while (<FILE>) { print MAIL; } close FILE; close (MAIL); &successs; } sub successs{ $JSCRIPTT=<<ENDD; document.cookie = "email=$email_entered", expires="+1y"; ENDD print $q->header(-type=>'text/html', accept=>'*/*'); print $q->start_html(-title=>'-Email Added Successfully!', -script=>$J +SCRIPTT); print "<h1><font color='#000080'>SUCCESS!</h1><br><br>\n"; print <<ENDOF; <p><b>Your Email address: </font><font color='red' size='+2'> \"$email +_entered\" </font><font color='#000080'>was added successfully!<br></ +b> You should be getting your first mail shortly!</p> ENDOF print $q->end_html; exit; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: CGI, cookies, sendmail, HTML attachments, searching txt files,
by projekt21 (Friar) on Oct 26, 2001 at 13:17 UTC | |
|
Re: CGI, cookies, sendmail, HTML attachments, searching txt files,
by projekt21 (Friar) on Oct 26, 2001 at 13:20 UTC | |
|
Re: CGI, cookies, sendmail, HTML attachments, searching txt files,
by projekt21 (Friar) on Oct 26, 2001 at 13:26 UTC | |
by Hofmator (Curate) on Oct 26, 2001 at 13:45 UTC |