Talonsrest
09-01-2006, 01:07 PM
I am trying to build a form that e-mails the data it collects to some address. I've had the HTML forum look at the page and they directed me to this forum to have the scripts looked at as they don't see anything wrong with the form itself.
I've tried a number of different ways to create this script but with no success. The tests on the web page all work fine. If I test each script using command lines, they work fine as well. If I put the two parts together, the page will launch the script but the script sends a formatted e-mail but with blanks where the values should be.
servmailer.pl v3.0
#!/usr/local/bin/perl
use Net::SMTP;
read(STDIN,$temp,$ENV{'CONTENT_LENGTH'});
@pairs=split(/&/,$temp);
foreach $item(@pairs)
{
($key,$content)=split(/=/,$item,2);
$content=~tr/+/ /;
$content=~s/%(..)/pack("c",hex($1))/ge;
$fields{$key}=$content;
}
# Build the e-mail body
$subject = "Subject: New Server Request \n";
$newline = "\n";
$line1 = " would like to request a server\n";
$line2 = "Ram = ";
$line3 = "\nHard Drive =";
@message = ($subject, $newline, $fields{name}, $line1, $line2, $fields{ram} , $line3, $fields{harddrive});
# Email the form results
$smtp = Net::SMTP->new("conference.co.marin.ca.us");
$smtp->mail("mwarden\@co.marin.ca.us");
$smtp->to("mwarden\@co.marin.ca.us");
$smtp->data(@message);
$smtp->quit;
servmailer.pl v2.0
#!/usr/local/bin/perl
use CGI;
use Net::SMTP;
# Create the CGI object
my $query = new CGI;
# Output the HTTP header
print $query->header ( );
# Capture the form results
my $name = $query->param("name");
my $ram = $query->param("ram");
my $harddrive = $query->param("harddrive");
# Build the e-mail body
$subject = "Subject: New Server Request \n";
$newline = "\n";
$line1 = " would like to request a server\n";
$line2 = "Ram = ";
$line3 = "\nHard Drive =";
@message = ($subject, $newline, $name, $line1, $line2, $ram, $line3, $harddrive);
# Email the form results
$smtp = Net::SMTP->new("conference.co.marin.ca.us");
$smtp->mail("mwarden\@co.marin.ca.us");
$smtp->to("mwarden\@co.marin.ca.us");
$smtp->data(@message);
$smtp->quit;
servmailer.pl v1.0
#! /usr/local/bin/perl -w
use Net::SMTP;
use CGI qw(:standard);
# Build the message
$subject = "Subject: New Server Request \n";
$newline = "\n";
$line1 = " would like to request a server\n";
$line2 = "Ram = ";
$line3 = "\nHard Drive =";
@message = ($subject, $newline, param('name'), $line1, $line2, param('ram'), $line3, param('harddrive'));
# E-mail the message
$smtp = Net::SMTP->new("conference.co.marin.ca.us");
$smtp->mail("mwarden\@co.marin.ca.us");
$smtp->to("mwarden\@co.marin.ca.us");
$smtp->data(@message);
$smtp->quit;
I built this script to just dump the values passed to it to a file to try to figure out what was going on.
Dump2file.pl
#! /usr/local/bin/perl -w
use Net::SMTP;
use CGI qw(:standard);
$myfile = 'C:\temp\test.txt';
$errfile = 'c:\temp\err.txt';
open(FILE, ">$myfile") or die "cant find file\n";
open STDERR, ">$errfile";
print FILE param('name'), "\n";
print FILE param('ram'), "\n";
print FILE param('harddrive');
close FILE;
In all cases, the script does execute, but the results are as if no information is being passed to the scripts.
I am creating this on a XP professional machine. I've tried it with IIS installed. I removed IIS and tried it with Apache installed just to see if it was the web engine. Could it be something with XP passing the information incorrectly?
I'm stumped, Anyone?
Here is the web page in case anyone wants to test it on their own.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/transitional.dtd">
<html>
<head><title>Test Server Form</title></head>
<body>
<form action="servmailer.pl" method="get" >
<p>
<h4>Name:</h4>
<input name='name' class="required" />
<h4>Memory</h4>
</p>
<p>
<SELECT name='ram' class="required">
<option selected value=128>128 Meg</option>
<option value=256>256 Meg</option>
<option value=512>512 Meg</option>
<option value=1024>1 Gig</option>
</select>
</p>
<p>
Hard Drive:
<select name='harddrive' class="required">
<option selected value=18>18 Gig</option>
<option value=40>40 Gig</option>
<option value=128>80 Gig</option>
<option value=128>120 Gig</option>
</select>
</p>
<p>
<input type="submit" value="Send" />
</p>
</form>
</body>
</html>
I've tried a number of different ways to create this script but with no success. The tests on the web page all work fine. If I test each script using command lines, they work fine as well. If I put the two parts together, the page will launch the script but the script sends a formatted e-mail but with blanks where the values should be.
servmailer.pl v3.0
#!/usr/local/bin/perl
use Net::SMTP;
read(STDIN,$temp,$ENV{'CONTENT_LENGTH'});
@pairs=split(/&/,$temp);
foreach $item(@pairs)
{
($key,$content)=split(/=/,$item,2);
$content=~tr/+/ /;
$content=~s/%(..)/pack("c",hex($1))/ge;
$fields{$key}=$content;
}
# Build the e-mail body
$subject = "Subject: New Server Request \n";
$newline = "\n";
$line1 = " would like to request a server\n";
$line2 = "Ram = ";
$line3 = "\nHard Drive =";
@message = ($subject, $newline, $fields{name}, $line1, $line2, $fields{ram} , $line3, $fields{harddrive});
# Email the form results
$smtp = Net::SMTP->new("conference.co.marin.ca.us");
$smtp->mail("mwarden\@co.marin.ca.us");
$smtp->to("mwarden\@co.marin.ca.us");
$smtp->data(@message);
$smtp->quit;
servmailer.pl v2.0
#!/usr/local/bin/perl
use CGI;
use Net::SMTP;
# Create the CGI object
my $query = new CGI;
# Output the HTTP header
print $query->header ( );
# Capture the form results
my $name = $query->param("name");
my $ram = $query->param("ram");
my $harddrive = $query->param("harddrive");
# Build the e-mail body
$subject = "Subject: New Server Request \n";
$newline = "\n";
$line1 = " would like to request a server\n";
$line2 = "Ram = ";
$line3 = "\nHard Drive =";
@message = ($subject, $newline, $name, $line1, $line2, $ram, $line3, $harddrive);
# Email the form results
$smtp = Net::SMTP->new("conference.co.marin.ca.us");
$smtp->mail("mwarden\@co.marin.ca.us");
$smtp->to("mwarden\@co.marin.ca.us");
$smtp->data(@message);
$smtp->quit;
servmailer.pl v1.0
#! /usr/local/bin/perl -w
use Net::SMTP;
use CGI qw(:standard);
# Build the message
$subject = "Subject: New Server Request \n";
$newline = "\n";
$line1 = " would like to request a server\n";
$line2 = "Ram = ";
$line3 = "\nHard Drive =";
@message = ($subject, $newline, param('name'), $line1, $line2, param('ram'), $line3, param('harddrive'));
# E-mail the message
$smtp = Net::SMTP->new("conference.co.marin.ca.us");
$smtp->mail("mwarden\@co.marin.ca.us");
$smtp->to("mwarden\@co.marin.ca.us");
$smtp->data(@message);
$smtp->quit;
I built this script to just dump the values passed to it to a file to try to figure out what was going on.
Dump2file.pl
#! /usr/local/bin/perl -w
use Net::SMTP;
use CGI qw(:standard);
$myfile = 'C:\temp\test.txt';
$errfile = 'c:\temp\err.txt';
open(FILE, ">$myfile") or die "cant find file\n";
open STDERR, ">$errfile";
print FILE param('name'), "\n";
print FILE param('ram'), "\n";
print FILE param('harddrive');
close FILE;
In all cases, the script does execute, but the results are as if no information is being passed to the scripts.
I am creating this on a XP professional machine. I've tried it with IIS installed. I removed IIS and tried it with Apache installed just to see if it was the web engine. Could it be something with XP passing the information incorrectly?
I'm stumped, Anyone?
Here is the web page in case anyone wants to test it on their own.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/transitional.dtd">
<html>
<head><title>Test Server Form</title></head>
<body>
<form action="servmailer.pl" method="get" >
<p>
<h4>Name:</h4>
<input name='name' class="required" />
<h4>Memory</h4>
</p>
<p>
<SELECT name='ram' class="required">
<option selected value=128>128 Meg</option>
<option value=256>256 Meg</option>
<option value=512>512 Meg</option>
<option value=1024>1 Gig</option>
</select>
</p>
<p>
Hard Drive:
<select name='harddrive' class="required">
<option selected value=18>18 Gig</option>
<option value=40>40 Gig</option>
<option value=128>80 Gig</option>
<option value=128>120 Gig</option>
</select>
</p>
<p>
<input type="submit" value="Send" />
</p>
</form>
</body>
</html>