Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

E-mail from html page 1

Status
Not open for further replies.

jeffsurfs

MIS
Aug 9, 2001
19
US
I have the following code and when I "get" it from the html it shows the code in the browser window. I am new to the server I am using so may not be directing something right. Also, the pl program is in the same directory as the html, maybe it has to be in a cgi folder, I don't know. Does the program look alright? I am having a lot of problems with Perl and CGI so any help would be appreciated.

Thanks

email.pl



#!/usr/bin/perl


%postInputs = readPostInput();

open (MAIL, "|/usr/sbin/sendmail -t") || return 0;


select (MAIL);
print<<&quot;EOF&quot;;
To: JeffJ\ @wayne-ent.com
From: $postInputs{ 'email' }
Subject: Message Board Reply

Email Registration
Name: $postInputs{ 'TheName' }
Email: $postInputs{ 'Email' }
Company Name: $postInputs{ 'Company'}
Address: $postInputs{ 'address' }
Phone: $postInputs{ 'Number' }
Contact: $postInputs{ 'Contact' }
Info: $postInputs{ 'Info' }


EOF

close(MAIL);
select(STDOUT);
printThankYou();

sub readPostInput(){
my(%searchField, $buffer, $pair, @pairs);
if($ENV{ 'REQUEST_METHOD'} eq 'POST'){
read(STDIN, $buffer, $ENV{ 'CONTENT_LENGTH'} );
@pairs = split(/&/, $buffer);
foreach $pair (@pairs){
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])
/pack(&quot;C&quot;, hex($1))/eg;
$name =~ tr/+/ /;
$name =~ s/%([a-fA-F0-9][a-fA-F0-9])
/pack(&quot;C&quot;, hex($1))/eg;
$searchField{ $name} = $value;
}
}
return (%searchField);
}

sub printThankYou(){
print<<&quot;EOF&quot;;
Content-Type: text/html

<HEAD>
<TITLE>THANK YOU FOR REGISTERING!</TITLE>
<META HTTP-EQUIV=&quot;Content-Type&quot; CONTENT=&quot;document&quot;>
</HEAD>
<BODY>
<TABLE CELLSPACING=2 CELLPADDING=2 border=0 width=600>
<TR>
<BR>
<CENTER>
<FONT SIZE=+3><B>Thank You</b> </font></center><BR><BR>
<CENTER><B> <FONT SIZE=+1>
<P>Thank you $postInputs{ 'Name' } for regisering <BR>
</FONT></B><CENTER>
</TD>
</TR>
</TABLE>

</BODY>
</HTML>

EOF
}
 
I started with this stuff last week, but i can tell you that your script must be in the cgi-bin. Also you may want to give the program a .cgi file extension. From my cgi/perl tutorial:
&quot;There is still one bug that usually bites the more experienced programmers more often than the inexperienced folks. The filename extension must be correct. We experienced (old) guys and gals know that the filename extensions don't really mean anything, so we are more likely to ignore the file-naming convention of filename.cgi for CGI programs. This is a big mistake! The Web server really does use that filename extension to determine what it is supposed to do with the file requested by the browser. So use the correct file extension! It's probably .cgi, but check the srm.conf file found below the server root directory in the configuration directory because it has the correct file extension. Look for something like this:
AddType application/x-httpd-cgi .cgi
You will save a great deal of debugging time if you always check these things first:
„h Always check your file permissions; your CGI program should be executable.
„h Always try your program first from the command line.
„h Make sure that you are sending a blank line after your last response header.
„h Make sure that the filename extension on your CGI program matches the one in the srm.conf file.&quot;

Always make sure you leave a blank line after EOF, this has screwed up many of my programs recently. Also the brackets in print<<&quot;EOF&quot;; are not nescessarry and may be causing problems. I would try seperating the Content-Type: text/html from the rest of the stuff, and don't forget to leave a blank line after it. It should be written like this: print &quot;Content-type: text/html\n\n&quot;; I do not no if it is a problem the way you put it, but it's best to eliminate as many possible problems as you can when debugging a script. That is about the extent I can help you, I'm not at the point yet where I can understand more than half of what you did there:) Hope this helps anyways.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top