Solved

cgi email script error

Posted on 2001-06-21
9
223 Views
Last Modified: 2012-05-04
  Keep getting 'ERROR Please check the sender's email address setting.' when I submit on a form.

   Check out http://www.techinc.org/apply.html for example.
0
Comment
Question by:Bob Stone
  • 3
  • 2
  • 2
  • +1
9 Comments
 
LVL 7

Expert Comment

by:daniel_c
ID: 6215879
post your mailform.pl script (even though, this should be under PERL forum).
0
 
LVL 19

Expert Comment

by:webwoman
ID: 6216109
Lots of those mail scripts require that you set the referrer domain before they'll work, and almost all of them require that you have a valid e-mail address in the FROM field. If you don't have something for that, they won't send.

Check the documentation for the mail script you used. If your hosting company provided it, check with them. Form handlers are pretty picky about how they're set up, and it sounds like you're missing a required value for the script.
0
 
LVL 9

Author Comment

by:Bob Stone
ID: 6216130
#!/usr/bin/perl

                         ### *** IMPORTANT *** ###

       ### *** Make sure the path to PERL above is correct - Unix Servers Only*** ###



# CONFIGURE THE VARIABLES BELOW FOR YOUR SERVER STARTING ON
# LINE 53


      #################################################################
      #                                                               #
      #                       Mail Form Ver 2.2                       #
      #                                                               #
      #                              by                               #
      #                        Ranson Johnson                         #
      #                                                               #
      # E-Mail: ranson@rlaj.com                                       #
      #                                                               #
      # Script name: mailform.pl                                      #
      #                                                               #
      # Copywrite 1997/2000 by Ranson's Scripts all rights reserved   #
      # Sale or re-distribution of this program without prior written #
      # permision is prohibited. you may modify this program for      #
      # your own use.                                                 #
      #################################################################


                      ### *** IMPORTANT *** ###

### *** If FTP'ing this file, be sure to send in ASCII format *** ###

# You must chmod the cgi's to 755
# For information on chmod see Ranson's FAQ's

#  Configure the varialbles in the configuration section below
#    be careful to not disturb the single (') or double quotes (")
#    surounding each variable, or the semicolon (;) at the end of
#    each line.


# This program is set up for Unix mail - Sendmail - /usr/sbin/sendmail
#
# And NT mail SendMail.pm - A mail module for NT Servers
#
# Ask your server admin for the SMTP server to use for your mail.
#
# If you need the path to the require 'SendMail.pm'
# ASK YOUR SERVER ADMINISTRATOR FOR THE PATH TO THIS DIRECTORY
#
# We can not help with this.

# The securiety variable below is to keep users from accessing this program
# from their computer or another server.
# If you want access from only your server, set the variable below to '1'
$secure_access = '1';

# Operating System = 'windows' or 'unix' (Case Sensitive)
$operating_system = "windows";

# For Windows, you must define the SMTP Server
$Define_SMTP_Server = "www.techinc.org";

# Windows mail debugging  1 = debug   0 = debug off
$Set_Debug = "0";

# Unix mail program (sendmail)
$mailprog = "/usr/cgi/sendmail";


            ### *** DO NOT CHANGE ANYTHING BELOW*** ###

                        ### *** :) *** ###

                        ### *** :) *** ###

                        ### *** :) *** ###



&parse_data;

print "Content-Type: text/html\n\n";

if($ENV{'HTTP_REFERER'} !~ /$ENV{'SERVER_NAME'}/ && $secure_access eq "1") { &invalid_referer; }


            ### *** Check for Required Fields *** ###




if ($FORM{'REQUIRED'} ne "") {
@Required = split(/,/,$FORM{'REQUIRED'});
foreach $field (sort(@Required)) {
&required("$field") unless($FORM{$field} ne "");
 }
}
&format_mail;


                 ### *** SEND THE MAIL *** ###

sub format_mail {

if ($FORM{'XX-sort'} =~ /yes/i) {
@Form_Data = sort(@FORM);
}else{
@Form_Data = @FORM;
}

if ($FORM{'XX-Sort_Order'}) {
@sort_fields = split(/,/, $FORM{'XX-Sort_Order'});
foreach $sortfield(@sort_fields) {
foreach $formfield (@Form_Data) {
    ($key, $val) = split(/=/,$formfield);
    $key =~ s/%(..)/pack("c",hex($1))/ge;
    $val =~ s/%(..)/pack("c",hex($1))/ge;
if (($key eq "$sortfield")) {
$Mail_Body .= "$key - $val\n\n";
   }
  }
 }
}else{
foreach $formfield (@Form_Data) {
    ($key, $val) = split(/=/,$formfield);
    $key =~ s/%(..)/pack("c",hex($1))/ge;
    $val =~ s/%(..)/pack("c",hex($1))/ge;
if ($key !~ /XX|REQUIRED/) {
$Mail_Body .= "$key - $val\n\n";
  }
 }
}
if ($FORM{'XX-attach_file'} && ($operating_system =~ /unix/i)) {
$User_mail_body .= "\n";
  open (TEXT, "uuencode $FORM{'XX-attach_file'} $FORM{'XX-attach_file_name'} |");
  while (<TEXT>)  {
    $User_mail_body .= $_;
  }
 close TEXT;
}
if ($FORM{'XX-attach_file'} && ($operating_system =~ /windows/i)) {
$User_mail_body .= "\n";
  open (TEXT, "$FORM{'XX-attach_file'}");
  while (<TEXT>)  {
    $User_mail_body .= $_;
  }
 close TEXT;
}
if ($operating_system =~ /windows/i) {
&windows_mail;
}else{
&unix_mail;
 }
} # End sub format_mail


                ### *** DO NOT EDIT BELOW *** ###

sub unix_mail {

if ($FORM{'XX-MailProgram'} && (!-e "$mailprog")) {
&open_error("The mail program is incorrect for your server. $mailprog");
}

        open (MAIL, "|$mailprog -t -oi -oem");
        print MAIL"To: $FORM{'XX-send-to-email'}\n";
        print MAIL"From: $FORM{'XX-email'}\n";
        print MAIL"Subject: $FORM{'XX-subject'}\n\n";
        print MAIL "$Mail_Body";
        close (MAIL);

# Send Receipt mail
if ($FORM{'XX-Send-Receipt'} eq "1") {
        open (MAIL, "|$mailprog -t -oi -oem");
        print MAIL"To: $FORM{'XX-send'}\n";
        print MAIL"From: $FORM{'XX-email-to-email'}\n";
        print MAIL"Subject: $FORM{'XX-receipt-mail-subject'}\n\n";
        print MAIL "$FORM{'XX-Receipt-Mail-Body'}\n\n";
        print MAIL "$User_mail_body";
        close (MAIL);
 }
} # End unix mail

                        ### *** :) *** ###


sub windows_mail {
eval {
$path = $0;
$filename = $path;
            
            $filename =~ s/^.*\\//;
            $path =~ s/$filename//;
            $path =~ s/\\$//;
            unshift (@INC, "$path");
            require 'SendMail.pm';  
                  };
        if ($@) {
                print "<PRE>\n\n";
        if ($! =~ /No such file/i) {
                print "Error Finding the SendMail.pm File: \n\n";
                print "$@\n";
                print "Make sure the SendMail.pm file is in this directory.\n";
                print "You may need to put the complete path in the require statement.\n\n";
                print "The require statement is on line 180 of this file.\n";
                print "$0";
                print "</PRE>";
        }
}

# WINDOWS MAIL

$sm = new SendMail("$Define_SMTP_Server");
if ($Set_Debug eq "1") {
$sm->setDebug($sm->ON);
}else{
$sm->setDebug($sm->OFF);
}$sm->From("$FORM{'XX-email'}");
$sm->Subject("$FORM{'XX-subject'}");
$sm->To("$FORM{'XX-send-to-email'}");
$sm->setMailBody("$Mail_Body");
if ($sm->sendMail() != 0) {
print "Content-type: text/html\n\n";
print "\n\nERROR\n\n";
  print $sm->{'error'}."\n";
  exit -1;
 }

if ($FORM{'XX-Send-Receipt'} eq "1") {
$sm = new SendMail("$Define_SMTP_Server");
$sm->setDebug($sm->OFF);
$sm->From("$FORM{'XX-send-to-email'}");
$sm->Subject("$FORM{'XX-receipt-mail-subject'}");
$sm->To("$FORM{'XX-email'}");
$sm->setMailBody("$FORM{'XX-Receipt-Mail-Body'}\n\n$User_mail_body");
if ($sm->sendMail() != 0) {
print "Content-type: text/html\n\n";
print "\n\nERROR\n\n";
  print $sm->{'error'}."\n";
  exit -1;
  }
 }
} # End windows mail


                   ### *** Redirect *** ###

if ($FORM{'XX-redirect-to-url'} ne "") {
    print <<"~EOT~";
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<title></title>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-1">
<META HTTP-EQUIV="Refresh" CONTENT="0; URL=$FORM{'XX-redirect-to-url'}"></HEAD>
<BODY BGCOLOR="FFFFFF">
</BODY>
</HEAD>
~EOT~
}else{
           ### *** Just Print Thank You Screen *** ###

    print <<"EOT";

<HTML>
<HEAD>
<TITLE>Mail Sent</TITLE>
</HEAD>
<BODY BGCOLOR=#FFFFFF Link=#0000FF vlink=#1D307E>
<P>
<B><FONT COLOR=000000 SIZE=+2>Thank You</FONT>
<BR>
<FONT COLOR=FF0000 SIZE=+1>Your Mail Has Been Sent</FONT></B>
<P>
&nbsp;
<P>
</BODY>
</HTML>

EOT
        ## DO NOT DISTURB THE LINE ABOVE
exit;
}


                         ### *** END OF PROGRAM *** ###

sub parse_data {

  local (*FORM) = @_ if @_;
  local ($i, $key, $val);

  # Read in text
  if ($ENV{'REQUEST_METHOD'} eq "GET") {
    $FORM = $ENV{'QUERY_STRING'};
  }
  elsif ($ENV{'REQUEST_METHOD'} eq "POST") {
    read(STDIN,$FORM,$ENV{'CONTENT_LENGTH'});
  }
  @FORM = split(/[&;]/,$FORM);
  foreach $i (0 .. $#FORM)
  {
    # Convert plusses to spaces
    $FORM[$i] =~ s/\+/ /g;

    # Split into key and value
    # splits on the first =
    ($key, $val) = split(/=/,$FORM[$i],2);

    # Convert %XX from hex numbers to alphanumeric
    $key =~ s/%(..)/pack("c",hex($1))/ge;
    $val =~ s/%(..)/pack("c",hex($1))/ge;

    $val =~ s/`//g;
    $val =~ s/\*//g;
    $val =~ s/<!--(.|\n)*-->//g;
    $FORM{$key} .= "\0" if (defined($FORM{$key}));
    $FORM{$key} .= $val;
  }
  return scalar(@FORM);
 
} # End sub parse


                         ### *** *** ###

sub required {

    local ($errorname) = @_;
    $errorname =~ s/XX\-//;
    print <<"EOT";

<HTML>
<HEAD>
<TITLE>Form Error!</TITLE>
</HEAD>
<BODY BGCOLOR=#FFFFFF Link=#0000FF vlink=#1D307E>
<P>
<B><FONT COLOR=000000 SIZE=+2>Form Error</FONT>
&nbsp; &nbsp;
<FONT COLOR=FF0000 SIZE=+2>$errorname</FONT></B>
<P>
&nbsp;
<P>
<CENTER>
<B><FONT FACE="Arial" COLOR="000080" SIZE="+1">
A Required field on the form has been left blank.
<BR>
Please go back to the form and check the field.</FONT></B>
<P>
<form><input type="button" value="BACK" onClick=history.back()>
<P>
</CENTER>
</BODY>
</HTML>

EOT
        ## DO NOT DISTURB THE LINE ABOVE
exit;
}

                         ### *** *** ###

sub open_error
    {

    local ($errorname) = @_;
    print <<"EOT";
<HTML>
<HEAD>
<TITLE>Open Error!</TITLE>
</HEAD>
<BODY BGCOLOR=#FFFFFF Link=#0000FF vlink=#1D307E>
<P>
<HR>
<P>
<H1>Error!</H1>
<P>
<H3>$errorname</H3>
<P>
<B>$!</B>  
<P>
</BODY>
</HTML>

EOT

exit;
} # End sub open_error


sub format_error {

    local ($errorname) = @_;
    print <<"EOT";
<HTML>
<HEAD>
<TITLE>Open Error!</TITLE>
</HEAD>
<BODY BGCOLOR=#FFFFFF Link=#0000FF vlink=#1D307E>
<P>
<HR>
<P>
<H1>Error!</H1>
<P>
<H3>$errorname</H3>
<P>
</BODY>
</HTML>
EOT
exit;
}

                        ### *** :) *** ###

sub invalid_referer {

print <<"Close~//~Print";
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<title>Referer Error</title>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-1">
</HEAD>
<BODY BGCOLOR="#EEF3F9" TEXT="#000000">
<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 Width="100%">
<TR>
        <TH BGCOLOR="#D0D8EA" Colspan=4><BR>
<B><FONT SIZE="+3">An Error Has Occured - Invalid Referer</FONT></B>

</TH>
</TR>
<TR>
<TD BGCOLOR="#D0D8EA"><FONT SIZE="-3">&nbsp;</FONT></TD><TD BGCOLOR="#000080" Colspan=3><FONT SIZE="1">&nbsp;</FONT></TD>
</TR>
<TR>
<TD BGCOLOR="#D0D8EA"><FONT SIZE="6">&nbsp;</FONT></TD><TD BGCOLOR="#000080"><FONT SIZE="6">&nbsp;</FONT></TD><TD BGCOLOR="#D0D8EA" Colspan=2><FONT SIZE="1">&nbsp;</FONT></TD>
</TR>
<TR>
<TD BGCOLOR="#D0D8EA" Width="5%">
<P>&nbsp;<P>&nbsp;<P>&nbsp;<P>&nbsp;<P>&nbsp;<P>&nbsp;<P>&nbsp;<P>&nbsp;<P>&nbsp;<P>&nbsp;<P>&nbsp;<P>
</TD>
<TD BGCOLOR="#000080" Width="2%"><FONT SIZE="1">&nbsp;</FONT></TD>
<TD BGCOLOR="#D0D8EA" Width="5%">&nbsp;</TD>
<TD Valign=top>
<BR><BR>
<CENTER>
<B><FONT COLOR="#A6471A" SIZE="+1">
The System Administrator has determined that this program
<BR>
can not be accessed from the page you came from.
</FONT></B>
<P>
<FORM>
<TABLE BORDER=1 BGCOLOR=#FF0000 cellpadding=3 cellspacing=0>
<TR><TD>
<input type="button" value="BACK" onClick=history.back()></TD>
</TR></TABLE>
</FORM>
<P>
<B><FONT COLOR="#621E42" SIZE="+1">Please go back to the Previous page and inform the webmaster.</FONT>
<P>&nbsp;<P>
<FONT COLOR="" SIZE="">If you feel this is in error, contact the
<A HREF="mailto:$FORM{'XX-send-to-email'}">webmaster</A> for this site.</FONT>
</CENTER>
</TR>
</TABLE>

<P>&nbsp;<P>&nbsp;<P>&nbsp;<P>&nbsp;<P>&nbsp;<P>
</BODY>
</HTML>
Close~//~Print
exit;
}

                        ### *** :) *** ###



__END__

0
 
LVL 7

Expert Comment

by:daniel_c
ID: 6216266
First, read the comment of the author:
-------
# Ask your server admin for the SMTP server to use for your mail.
#
# If you need the path to the require 'SendMail.pm'
# ASK YOUR SERVER ADMINISTRATOR FOR THE PATH TO THIS DIRECTORY
-------
Do you have permission on this?


Secondly,
-------
# For Windows, you must define the SMTP Server
$Define_SMTP_Server = "www.techinc.org";
-------
Are you sure that the SMTP Server address is right?
(Usually: SMTP server is like this: smtp.domainname.com)

0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 8

Expert Comment

by:bebonham
ID: 6216508
- Unix Servers Only*** ###



don't forget it...

sendmail on my machine is at usr/sbin/sendmail


but if you use Mail::Mailer in perl, you can avoid having to worry about it...

like daniel_c says, ask in the perl ta
0
 
LVL 9

Author Comment

by:Bob Stone
ID: 6218496
  Well, I set the SMTP and the sendmail directory to what they should be, but it still doesn't work.

   Here is what I got on the variables, the rest is the same as above. Am I overlooking anything else?

# The securiety variable below is to keep users from accessing this program
# from their computer or another server.
# If you want access from only your server, set the variable below to '1'
$secure_access = '1';

# Operating System = 'windows' or 'unix' (Case Sensitive)
$operating_system = "windows";

# For Windows, you must define the SMTP Server
$Define_SMTP_Server = "smtp.techinc.org.hosting.swbell.net";

# Windows mail debugging  1 = debug   0 = debug off
$Set_Debug = "0";

# Unix mail program (sendmail)
$mailprog = "/usr/vde/bin/sendmail";
0
 
LVL 7

Expert Comment

by:daniel_c
ID: 6218523
Are you sure that:
$Define_SMTP_Server = "smtp.techinc.org.hosting.swbell.net";

is the SMTP name from your ISP?

It's a long name for just an SMTP.
0
 
LVL 8

Expert Comment

by:bebonham
ID: 6220681
port 25 is ringing at smtp.techinc.org.hosting.swbell.net

so that is not the problem :)


are you sure you are allowed to send on it??

I couldn't :)
0
 
LVL 19

Accepted Solution

by:
webwoman earned 50 total points
ID: 6220698
stone5150, I'm going to try to consolidate a bit...

You have to have permission to use the mail server.
Your page has to be on that domain, probably on that particular server.
The server has to support perl, and it has to be the right version.
The perl file has to be saved correctly.
You have to reference all the required modules correctly, have permission to use them, and know EXACTLY where they sit on the server.

If ANY ONE of those is wrong, it WILL NOT WORK.
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now