View Full Version : Mail Form Script Wanted
Peloton
03-30-2006, 03:24 PM
Hi, I need a Mail Form Script, but I need it so someone can enter their own email address and then 3 friends and for it to email these 4 email addresses to one address of mine so an auto reply can be set-up to reply to them, I don't need to keep a record of the addresses entered. I've used FormMail from http://www.scriptarchive.com/ which is excellent but only emails from one entered address. Thanks if you can help.
mlseim
03-30-2006, 11:50 PM
Give us a link to your form so we can see what
variables you are giving your text boxes.
Peloton
04-04-2006, 11:02 PM
Thanks for the reply, the form is here: http://www.pelotonwebdesigns.com/emailform.html
mlseim
04-05-2006, 04:28 AM
Give this a shot ... and change the name. Don't use "FormMail" as
a name because spamming robots look for that name. Define the
subject and recipient in your script, not your form. Also, you might
want to check for "cc" and "bcc", removing them if found. And,
check for more than 1 "@" at symbol in each email ... to make sure
someone doesn't do this: "joe@aol.com;bill@aol.com;john@aol.com"
There is a more efficient way to script this, but I wanted to
give you something you could figure out easily and make changes.
So with this script as a start, you can Google some Perl tutorials and
learn how to check for some of the things I listed above, and return
back to your "error page" if something looks wrong. This will get you
started ...
#!/usr/bin/perl
use CGI ':standard';
########################################################
$mailprogram = "/usr/sbin/sendmail"; #<-- Location of your sendmail program
$myemail = "email\@pelotonwebdesigns.com"; #<-- Your email address
########################################################
# Read Variables from the form
$email1=param('email');
$email2=param('email2');
$email3=param('email3');
$email4=param('email4');
# you can define these on the form, or define them here and remove them from the form.
$redirect=param('redirect');
$mfr=param('missing_fields_redirect');
########################################################
# Check for problems ... (you'll have to define your own problem checking here)
unless($email1){print "Location: $mfr\n\n";}
# Send all 4 emails to you using a loop ...
for($x=1; $x<4; $x++){
$sender=${"email$x"};
$subject="Your Voucher"; #<-- define your own subject ... don't let the form define it.
if($sender){
open (MAIL, "|$mailprogram -t") or die "Can't fork sendmail.\n";
print MAIL "To: $myemail\n";
print MAIL "From: $sender\n";
print MAIL "Subject: $subject\n\n";
print MAIL "=====================================================\n";
print MAIL "\n";
print MAIL "This email came from your website form.\n";
print MAIL "\n";
print MAIL "=====================================================\n";
print MAIL "\n";
close(MAIL);
}#if $sender
}#for loop
# goto the redirect page
print "Location: $redirect\n\n";
EDIT:
I see now you mentioned creating an auto-responder ...
With the script above, you can probably see that you could
send the first email to you (from $email1) telling you that
someone is referring you. Then, send an "automatic" message
to the other 3 emails. You'll have to do some logic and swap
some variables to redirect the $sender and $recipients ...
This would be a good Perl lesson for you.
Peloton
04-06-2006, 01:04 PM
Thanks for your time, I'm showing my absolute lack of knowledge of perl, does this script replace the FormMail script completely or do I replace some of the code in FormMail, I've tried running it on it's own but get an internal server error, I uploaded it in binary.
mlseim
04-06-2006, 01:43 PM
This can run on it's own ... give it it's own name.
Upload in ASCII mode, and CHMOD the file to 755.
Alter the name in your HTML form to the name you
give the script (instead of FormMail).
I tried the script before I posted it, so I know it works.
Peloton
04-06-2006, 03:06 PM
Really strange, I've uploaded it in ASCII, CHMOD to 755 and renamed it and changed the path in the html form, I've also added the correct sendmail path in the script but it still throws up an Internal Server Error. There must be something I've done wrong?
mlseim
04-06-2006, 05:20 PM
How about the "shebang" ... the very top line:
#!/usr/bin/perl
Is this what it should be for your webhost?
See what you have for your existing MailForm script.
Make it the same as that one (the script that works).
OR ... maybe it's the Perl CGI Module ...
Try this script with a manual parsing section:
#!/usr/bin/perl
########################################################
$mailprogram = "/usr/sbin/sendmail"; #<-- Location of your sendmail program
$myemail = "email\@pelotonwebdesigns.com"; #<-- Your email address
########################################################
# Read Variables from the form
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
if (length($buffer) < 5) {
$buffer = $ENV{QUERY_STRING};
}
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
$value =~ tr/+//;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ s/&//g;
$input{$name} = $value;
}
$email1 = $input{'email'};
$email2 = $input{'email2'};
$email3 = $input{'email3'};
$email4 = $input{'email4'};
# you can define these on the form, or define them here and remove them from the form.
$redirect=$input{'redirect'};
$mfr=$input{'missing_fields_redirect'};
########################################################
# Check for problems ... (you'll have to define your own problem checking here)
unless($email1){print "Location: $mfr\n\n";}
# Send all 4 emails to you using a loop ...
for($x=1; $x<4; $x++){
$sender=${"email$x"};
$subject="Your Voucher"; #<-- define your own subject ... don't let the form define it.
if($sender){
open (MAIL, "|$mailprogram -t") or die "Can't fork sendmail.\n";
print MAIL "To: $myemail\n";
print MAIL "From: $sender\n";
print MAIL "Subject: $subject\n\n";
print MAIL "=====================================================\n";
print MAIL "\n";
print MAIL "This email came from your website form.\n";
print MAIL "\n";
print MAIL "=====================================================\n";
print MAIL "\n";
close(MAIL);
}#if $sender
}#for loop
# goto the redirect page
print "Location: $redirect\n\n";
Peloton
04-07-2006, 05:34 PM
I've got it working at last, not sure what it was as I tried loads of combinations of things to get it to work, I eventually worked on it in windows, I usually use a mac, which I'm new to, but it still failed for a while, I also added -w to the first line and on the 2nd time of trying it worked! One more thing, it only sends out 3 emails, is this intentional as I need it to send out 4?
Many thanks for all your help and time, much appreciated, would you be able to recommend any web sites or books on learning perl for complete beginners obviously :-)
mlseim
04-07-2006, 07:12 PM
oh ... my bad ...
for($x=1; $x<4; $x++){
I think it should be:
for($x=1; $x<=4; $x++){
Less than or equal to 4, so it will send "$mail4"
.... books on Perl?
Search Amazon for any of the O'Reilly books.
There are some different level books.
FishMonger might know which one is best for you.
FishMonger
04-07-2006, 07:28 PM
for $x (1..4) {
Learning Perl, Fourth Edition (covers the basics)
http://www.oreilly.com/catalog/learnperl4/
Programming Perl, Third Edition ("required" reference book for all Perl programmers)
http://www.oreilly.com/catalog/pperl3/
Peloton
04-10-2006, 01:42 AM
Superb! Thanks guys!
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.