mightychest
Technical User
Hi,
I've spent a lot of time looking for a solution to this problem but have had no success (probably because I don't understand Perl well enough to make other people's code work for me).
I got some code from It was the best explained code that I could find so I stuck with it. I am making a website and on one page need the info entered into a form to be sent off to my email address. I also want another email to be sent to the sender with a copy of what they entered into the form.
The problem is the script just does not send any emails! Oddly, the form does not throw up any errors and it successfully redirects to the "message sent successfully" page. I am at a loss as to what the problem is.
My web host (also my ISP) has this page giving details on some of the ways to overcome problems with their frankly inadequate and frustrating system: It gives details on how to get Perl to work with them.
Any help would be greatly appreciated! This problem is making my hair fall out and my grades suffer.
Code below:
#!/usr/bin/perl
# location of Perl (above) - check your doc or ask admin
#############################################################
#
# Script Source: BrainCode.com
# Source URL: # Script Title: Alpha E-Mailer w/ Autoresponder
# Script Name: AlphaMail.pl
# Copyright: 1998,1999,2000 by OEC Corp & BrainCode.com
# Version: 09.01.1999.C (latest)
# Status: Fully tested, release version 7, Y2K ready
#
# This script may not be redistributed without this header
#
# There are no restrictions on this script - anyone may use
# it, though we appreciate credit where due. Responsibility
# for use of the script is entirely with the user. Please
# note that BrainCode.com does not support Perl scripts!
#
# Instructions:
#
# - Use WordPad.exe or any plain text editor to edit
# - Set your path to Perl as needed (first line at top)
# - Set ALL variables appropriately (below, see notes)
# - Take special care with the path to your sendmail (below)
# - Send the script to the server in ascii
# - Set script permissions - check your doc or ask admin
# - See a_faq.html for HTML set-ups in alphamail.zip file
# - Required html pages are also provided in alphamail.zip
#
#############################################################
##### SETTABLE VARIABLES ####################################
# URL to go to if there is a problem with form input
$ErrorPage = "
# URL to go to when form has been successfully submitted
$ThankPage = "
# URL to go to if a 'foreign' referer calls the script
$EvilReferer = "
# E-mail address to send intake form to (your address)
# If not using PERL 5, escape the @ thus: \@ instead of @
$YourEmail = '***@***.com';
# Script works only on your server(s) - ('URL1','URL2')
@referers = ('
# Location of mail program - check your doc or ask admin
$MailProgram = "/usr/lib/sendmail -f '$email' '***@***.com'";
# Subject of the e-mail autoreply to the submitter
$Subject = "***.com Autoreply";
# Header line in the auto-reply message
$Header = "Thank you for your enquiry. If you have requested any information from us we will do our best to revert to you as soon as possible.";
# Brief tail message for body of e-mail autoreply
$TailMessage = "Thank you for your contact.";
# Your signature lines the end of the autoreply e-mail
$Signature1 = "*** ***";
$Signature2 = "
##### END OF SETTABLE VARIABLES ############################
##### MAIN PROGRAM #########################################
&CheckReferingURL;
&ReadParse;
$title = $in{'title'};
$name = $in{'name'};
$lawfirmcompany = $in{'lawfirmcompany'};
$email = $in{'email'};
$telephone = $in{'telephone'};
$website = $in{'website'};
$country = $in{'country'};
$message = $in{'message'};
&CheckEmailAddressFormat;
&CheckFields;
&GetDate;
&SendSubmission;
&SendAutoReply;
print "Location: $ThankPage\n\n";
exit;
# _________________________________________________________
sub SendSubmission {
open (MAIL,"$MailProgram") || die "Content-Type: text/plain\n\nCan't send mail, sorry!\n";
print MAIL "To: $YourEmail\n";
print MAIL "From: $email\n";
print MAIL "Subject: $Subject\n";
print MAIL "$Date\n\n";
print MAIL "From: $title $name\n";
print MAIL "Law firm / company name: $lawfirmcompany\n";
print MAIL "Email: $email\n";
print MAIL "Telephone number: $telephone\n";
print MAIL "Website URL: $website\n";
print MAIL "Country: $country\n\n";
print MAIL "Message:\n\n";
print MAIL "$message\n\n";
print MAIL "-HOST:\t$ENV{'REMOTE_HOST'}\n";
print MAIL "-PAGE:\t$ENV{'HTTP_REFERER'}\n";
close (MAIL);
}
# _________________________________________________________
sub SendAutoReply {
open (MAIL,"$MailProgram") || die "Content-Type: text/plain\n\nCan't send mail, sorry!\n";
print MAIL "To: $email\n";
print MAIL "From: $YourEmail\n";
print MAIL "Subject: $Subject\n";
print MAIL "$Header\n";
print MAIL "$Date\n\n";
print MAIL "$Subject\n\n";
print MAIL "You sent the following:\n\n";
print MAIL "==============================\n\n";
print MAIL "$Date\n\n";
print MAIL "Title: $title\n";
print MAIL "Name: $name\n";
print MAIL "Law firm / company name: $lawfirmcompany\n";
print MAIL "Email: $email\n";
print MAIL "Telephone number: $telephone\n";
print MAIL "Website URL: $website\n";
print MAIL "Country: $country\n\n";
print MAIL "Message:\n\n";
print MAIL "$message\n\n";
print MAIL "==============================\n\n";
print MAIL "$TailMessage\n\n";
print MAIL "Best regards,\n\n\n";
print MAIL "$Signature1\n";
print MAIL "$Signature2\n\n";
print MAIL "-HOST:\t$ENV{'REMOTE_HOST'}\n";
print MAIL "-PAGE:\t$ENV{'HTTP_REFERER'}\n";
close (MAIL);
}
# _________________________________________________________
sub GetDate {
@days = ('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
@months = ('01','02','03','04','05','06','07','08','09','10','11','12');
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
$year = $year+1900;
$Date = "$days[$wday] $months[$mon]/$mday/$year";
}
# _________________________________________________________
sub ReadParse { local (*in) = @_ if @_;
local ($i, $key, $val); if ( $ENV{'REQUEST_METHOD'} eq "GET" )
{$in = $ENV{'QUERY_STRING'};}
elsif ($ENV{'REQUEST_METHOD'} eq "POST")
{read(STDIN,$buffer,$ENV{'CONTENT_LENGTH'});}
else {
$in = ( grep( !/^-/, @ARGV )) [0];
$in =~ s/\\&/&/g; } @in = split(/&/,$in);
foreach $i (0 .. $#in) {
$in[$i] =~ s/\+/ /g;
($key, $val) = split(/=/,$in[$i],2);
$key =~ s/%(..)/pack("c",hex($1))/ge;
$val =~ s/%(..)/pack("c",hex($1))/ge;
$in{$key} .= "\0" if (defined($in{$key}));
$in{$key} .= $val; } return length($in); }
# _________________________________________________________
sub CheckEmailAddressFormat {
if (index($email, "@") < 1) {&DoEmailError;}
#if (index($email, ".") < 1) {&DoEmailError;}
if (index($email, " ") > -1) {&DoEmailError;}
}
sub CheckFields {
if (!$name || $name eq ' ') {&DoEmailError;}
if (!$email || $email eq ' ') {&DoEmailError;}
if (!$message || $message eq ' ') {&DoEmailError;}
}
sub DoEmailError {
print "Location: $ErrorPage\n\n";
exit;
}
# _________________________________________________________
sub CheckReferingURL {
if ($ENV{'HTTP_REFERER'}) {
foreach $referer (@referers) {
if ($ENV{'HTTP_REFERER'} =~ /$referer/i) {
$check_referer = '1';
last;
}}}
else {$check_referer = '1';}
if ($check_referer != 1) {
print "Location: $EvilReferer\n\n";
exit;
}}
# _________________________________________________________
exit;
##### End of Script ########################################
I've spent a lot of time looking for a solution to this problem but have had no success (probably because I don't understand Perl well enough to make other people's code work for me).
I got some code from It was the best explained code that I could find so I stuck with it. I am making a website and on one page need the info entered into a form to be sent off to my email address. I also want another email to be sent to the sender with a copy of what they entered into the form.
The problem is the script just does not send any emails! Oddly, the form does not throw up any errors and it successfully redirects to the "message sent successfully" page. I am at a loss as to what the problem is.
My web host (also my ISP) has this page giving details on some of the ways to overcome problems with their frankly inadequate and frustrating system: It gives details on how to get Perl to work with them.
Any help would be greatly appreciated! This problem is making my hair fall out and my grades suffer.
Code below:
#!/usr/bin/perl
# location of Perl (above) - check your doc or ask admin
#############################################################
#
# Script Source: BrainCode.com
# Source URL: # Script Title: Alpha E-Mailer w/ Autoresponder
# Script Name: AlphaMail.pl
# Copyright: 1998,1999,2000 by OEC Corp & BrainCode.com
# Version: 09.01.1999.C (latest)
# Status: Fully tested, release version 7, Y2K ready
#
# This script may not be redistributed without this header
#
# There are no restrictions on this script - anyone may use
# it, though we appreciate credit where due. Responsibility
# for use of the script is entirely with the user. Please
# note that BrainCode.com does not support Perl scripts!
#
# Instructions:
#
# - Use WordPad.exe or any plain text editor to edit
# - Set your path to Perl as needed (first line at top)
# - Set ALL variables appropriately (below, see notes)
# - Take special care with the path to your sendmail (below)
# - Send the script to the server in ascii
# - Set script permissions - check your doc or ask admin
# - See a_faq.html for HTML set-ups in alphamail.zip file
# - Required html pages are also provided in alphamail.zip
#
#############################################################
##### SETTABLE VARIABLES ####################################
# URL to go to if there is a problem with form input
$ErrorPage = "
# URL to go to when form has been successfully submitted
$ThankPage = "
# URL to go to if a 'foreign' referer calls the script
$EvilReferer = "
# E-mail address to send intake form to (your address)
# If not using PERL 5, escape the @ thus: \@ instead of @
$YourEmail = '***@***.com';
# Script works only on your server(s) - ('URL1','URL2')
@referers = ('
# Location of mail program - check your doc or ask admin
$MailProgram = "/usr/lib/sendmail -f '$email' '***@***.com'";
# Subject of the e-mail autoreply to the submitter
$Subject = "***.com Autoreply";
# Header line in the auto-reply message
$Header = "Thank you for your enquiry. If you have requested any information from us we will do our best to revert to you as soon as possible.";
# Brief tail message for body of e-mail autoreply
$TailMessage = "Thank you for your contact.";
# Your signature lines the end of the autoreply e-mail
$Signature1 = "*** ***";
$Signature2 = "
##### END OF SETTABLE VARIABLES ############################
##### MAIN PROGRAM #########################################
&CheckReferingURL;
&ReadParse;
$title = $in{'title'};
$name = $in{'name'};
$lawfirmcompany = $in{'lawfirmcompany'};
$email = $in{'email'};
$telephone = $in{'telephone'};
$website = $in{'website'};
$country = $in{'country'};
$message = $in{'message'};
&CheckEmailAddressFormat;
&CheckFields;
&GetDate;
&SendSubmission;
&SendAutoReply;
print "Location: $ThankPage\n\n";
exit;
# _________________________________________________________
sub SendSubmission {
open (MAIL,"$MailProgram") || die "Content-Type: text/plain\n\nCan't send mail, sorry!\n";
print MAIL "To: $YourEmail\n";
print MAIL "From: $email\n";
print MAIL "Subject: $Subject\n";
print MAIL "$Date\n\n";
print MAIL "From: $title $name\n";
print MAIL "Law firm / company name: $lawfirmcompany\n";
print MAIL "Email: $email\n";
print MAIL "Telephone number: $telephone\n";
print MAIL "Website URL: $website\n";
print MAIL "Country: $country\n\n";
print MAIL "Message:\n\n";
print MAIL "$message\n\n";
print MAIL "-HOST:\t$ENV{'REMOTE_HOST'}\n";
print MAIL "-PAGE:\t$ENV{'HTTP_REFERER'}\n";
close (MAIL);
}
# _________________________________________________________
sub SendAutoReply {
open (MAIL,"$MailProgram") || die "Content-Type: text/plain\n\nCan't send mail, sorry!\n";
print MAIL "To: $email\n";
print MAIL "From: $YourEmail\n";
print MAIL "Subject: $Subject\n";
print MAIL "$Header\n";
print MAIL "$Date\n\n";
print MAIL "$Subject\n\n";
print MAIL "You sent the following:\n\n";
print MAIL "==============================\n\n";
print MAIL "$Date\n\n";
print MAIL "Title: $title\n";
print MAIL "Name: $name\n";
print MAIL "Law firm / company name: $lawfirmcompany\n";
print MAIL "Email: $email\n";
print MAIL "Telephone number: $telephone\n";
print MAIL "Website URL: $website\n";
print MAIL "Country: $country\n\n";
print MAIL "Message:\n\n";
print MAIL "$message\n\n";
print MAIL "==============================\n\n";
print MAIL "$TailMessage\n\n";
print MAIL "Best regards,\n\n\n";
print MAIL "$Signature1\n";
print MAIL "$Signature2\n\n";
print MAIL "-HOST:\t$ENV{'REMOTE_HOST'}\n";
print MAIL "-PAGE:\t$ENV{'HTTP_REFERER'}\n";
close (MAIL);
}
# _________________________________________________________
sub GetDate {
@days = ('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
@months = ('01','02','03','04','05','06','07','08','09','10','11','12');
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
$year = $year+1900;
$Date = "$days[$wday] $months[$mon]/$mday/$year";
}
# _________________________________________________________
sub ReadParse { local (*in) = @_ if @_;
local ($i, $key, $val); if ( $ENV{'REQUEST_METHOD'} eq "GET" )
{$in = $ENV{'QUERY_STRING'};}
elsif ($ENV{'REQUEST_METHOD'} eq "POST")
{read(STDIN,$buffer,$ENV{'CONTENT_LENGTH'});}
else {
$in = ( grep( !/^-/, @ARGV )) [0];
$in =~ s/\\&/&/g; } @in = split(/&/,$in);
foreach $i (0 .. $#in) {
$in[$i] =~ s/\+/ /g;
($key, $val) = split(/=/,$in[$i],2);
$key =~ s/%(..)/pack("c",hex($1))/ge;
$val =~ s/%(..)/pack("c",hex($1))/ge;
$in{$key} .= "\0" if (defined($in{$key}));
$in{$key} .= $val; } return length($in); }
# _________________________________________________________
sub CheckEmailAddressFormat {
if (index($email, "@") < 1) {&DoEmailError;}
#if (index($email, ".") < 1) {&DoEmailError;}
if (index($email, " ") > -1) {&DoEmailError;}
}
sub CheckFields {
if (!$name || $name eq ' ') {&DoEmailError;}
if (!$email || $email eq ' ') {&DoEmailError;}
if (!$message || $message eq ' ') {&DoEmailError;}
}
sub DoEmailError {
print "Location: $ErrorPage\n\n";
exit;
}
# _________________________________________________________
sub CheckReferingURL {
if ($ENV{'HTTP_REFERER'}) {
foreach $referer (@referers) {
if ($ENV{'HTTP_REFERER'} =~ /$referer/i) {
$check_referer = '1';
last;
}}}
else {$check_referer = '1';}
if ($check_referer != 1) {
print "Location: $EvilReferer\n\n";
exit;
}}
# _________________________________________________________
exit;
##### End of Script ########################################