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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

email from form programme

Status
Not open for further replies.

zakasa

Programmer
Nov 14, 2003
4
GB
I am a perl/cgi beginner and I have written a Perl script to email info entered into a form. I getting an error message which just say that there may be a scripting error. I am not sure what it is. Below is the script, please help.

#!/usr/bin/perl

%postInputs = readPostInput();
$dateCommand = "date";
$time = `$dateCommand`;
open (MAIL, "|/usr/sbin/sendmail -t") || return 0;

select (MAIL);
print << &quot;EOF&quot;;
To: sam\ @pterosaurtechnology.co.uk
From: $postInputs{ 'email'}
Subject: Questionaire Form

$time
Name: $postInputs{ 'name'}
Address1: $postInputs{ 'address1'}
Address2: $postInputs{ 'address2'}
Address3: $postInputs{ 'address3'}
Address4: $postInputs{ 'address4'}
DOB: $postInputs{ 'dob'}
Tel: $postInputs{ 'phone'}
Fax: $postInputs{ 'fax'}
Email: $postInputs{ 'email'}
Marital Status: $postInputs{ 'marital'}
No. of Children: $postInputs{ 'children'}
No of Dependants: $postInputs{ 'depend'}
Details of Dependants: $postInputs{ 'dependDetails'}
Close Relative in UK: $postInputs{ 'inUK'}
Close Relatives Overseas: $postInputs{ 'overseas'}
Qualifications: $postInputs{ 'qualifications'}
Present Employment: $postInputs{ 'employ'}
Present Salary: $postInputs{ 'salary'}
Spouses Employment: $postInputs{ 'spouseEmploy'}
Spouses Salary: $postInputs{ 'spouseSalary'}
Ancestry: $postInputs{ 'ancestry'}
Intentions: $postInputs{ 'intentions'}
Details: $postInputs{ 'previous'}


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</title>
<meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html;
charset=iso-8859-1&quot;>
</head>

<body bgcolor=&quot;#F7F7F7&quot;>
<div align=&quot;center&quot;>
<h2>THANK YOU</h2>
<h5>THANK YOU $postInputs{ 'name'} FOR SUBMITTING YOUR REQUEST FOR
INFORMATION.<br>
WE WILL GET BACK TO YOU AS SOON AS POSSIBLE.</h5>
</div>
</body>
</html>

EOF
}
 
I successfully ran this script on the CLI and via the web.

Recommendation:
Use the CGI.PM to parse incoming data.
 
Sorry, excuse my lack of knowledge. If you are saying that the script essentially works, could the problem I am having be with my host.
 
Yes they do allow CGI's. Thanks for you help, I will get onto my host and see if they can shed some light.
 
Try replacing this:
[tt]
#!/usr/bin/perl

%postInputs = readPostInput();
[/tt]
with this:
[tt]
#!/usr/bin/perl
use CGI;
use CGI::Carp qw(fatalsToBrowser);

CGI::ReadParse();
%postInputs = %in;
[/tt]
This should give you a more meaningful error message when the script fails, and uses the CGI module to parse form data as suggested by mbrooks.

-- Chris Hunt
 
Check your error logs, this 'scripting error' will be well defined there.

I think your dying at this point :

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

sendmail may not be located at that path, may not have the -t option or may not be executable by the user the webserver runs as. A '0' return value would generate no headers which would in turn potentially generate your error condition.

The error log would say best though.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top