On Wed, 19 Dec 2001 04:55:25 +0200, [EMAIL PROTECTED] (Christo Rademyer) wrote:
>Hi im looking for a simple perl mail program source code , program that takes your
>input and ask you for the address , etc,, and mail you the info to an address.
>Thanx 4 ur help.
>
Here's one I've been learning with.
There is an html form to submit, and a
cgi to sendmail, write a log, and issue a thank you
page.
I adapted it from a guestbook example, and added
strict and taint checking. I think the taint checking
could be improved. You can add any info you want
after the $comment variable in the outmail sub.
###########################################################
#!/usr/bin/perl -T
use strict;
#use diagnostics;
use warnings;
use CGI qw/:standard/;
my $sendmailpath = '/usr/sbin/sendmail';
# fields from html submit
my $name = param("name");
if ($name =~ /^([-\@\w.]+)$/){$name= $1;} #untaint
my $email = param("email");
if ($email =~ /^([-\@\w.]+)$/){$email= $1;}
my $comments = param("comments");
if ($comments =~ /^([-\@\w.]+)$/){$comments= $1;}
# this is the string that will be appended to the data file
my $information = "$name\|$email\|$comments";
sub outmail {
my $from = '[EMAIL PROTECTED]';
my $to = $email;
my $subject = 'Thank You!';
$ENV{PATH} = '/bin:/usr/bin'; #untaint
open (NEWMAIL,"|$sendmailpath -t")or die "Cannot open sendmail: $!";
print NEWMAIL<<THANKS;
Subject: $subject
From: $from
To: $to
Thank you for signing my guest book.
Your comments were:
$comments
#add other info here if you want
-- zentara
THANKS
close (NEWMAIL);
}
# Start prints form results, saves to file and outputs a ThankYou html.
print header();
start_html();
print "\n";
# Here's where it opens maildata for appending and adds $information to it
open (MAILDATA, ">>./maildata");
print MAILDATA
"$information\n####################################################\n";
close(MAILDATA);
# Then it prints a message to say that everything worked
if ($email) {
&outmail ;
print "<div align\=\"center\">Thanks for signing my guestbook<\/div><br>\n";
} else {
print "Thank you for visiting\n" ;
}
print "\n";
print end_html();
##########################################################################
#The html submit form
<html>
<head>
<title>Send us an e-mail...</title>
</head>
<body>
<font size="5">Send us an e-mail...</font><font size="4"><br></font>
<form action="cgi-bin/zmail.cgi" method="POST">
<p><font size="4">Your Name (required):</font><br>
<input type="text" name="name" size="50"></p>
<p><font size="4">Your E-mail (required):</font><br>
<input type="text" name="email" size="50"></p>
<p><font size="4">Your message (required):</font><br>
<textarea rows="16" name="comments" cols="80"></textarea></p>
<p><input type="submit" value="Click Once to Send" name="B1"> <input
type="reset" value="Clear" name="B2"></p>
</form>
</body>
</html>
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]