Three questions, Sorry!
1) I have set up a form so that people can submit there email addresses to my mailing list.
Ok I have been messing around with an autoreply and need to be able to send an "HTML" file with the autoreply thru sendmail. This way you get a GREAT email message instead of yucky text-on-text
Does anyone know how to do this?
2)Does anyone have a snippet of code that will check a existing .txt file for the email address entered and return "already added" to the user if they already added there email address? I cant seem to get one right.
3)Anyone know why The cookie i set below for +1y seems to not be there after i close my browser? Is it the way im reading it? I cant seem to use HTTP::cookie so i use $q->cookie().
heres a sample:
#!/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;
}