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

CGI error problem

Status
Not open for further replies.

NacNab

Instructor
Oct 28, 2003
9
GB
I am trying to get a CGI script to work

The result I keep getting is

“Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator, admin@teamhosts.com and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.

Apache/1.3.27 Server at Port 80”

The error log reads,

“malformed header from script. Bad header=Recipient names must be specif:”


Can anyone tell me what this might mean?
 
...sounds like a Sendmail Error. Try using the -t switch in the sendmail path.

Example:
$sendmail = '/usr/lib/sendmail -t';
 
Thanks vego
I have been trying that on and off throughout my tests.
It does lead me to the "success" page but I still do not receive the emails
 
Posting your script would help greatly...

There's always a better way. The fun is trying to find it!
 
This worked fine on a different server.

#!/usr/bin/perl

$mailprog = '/usr/sbin/sendmail -t';

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("C", hex($1))/eg;
$name =~ tr/+/ /;
$name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;

$FORM{$name} = $value;
}

$title = $FORM{'title'};
$name = $FORM{'name'};
$surname = $FORM{'surname'};
$email = $FORM{'email'};
$message = $FORM{'message'};


# Redirect user to FAIL page

if ($validationfailed == 1)
{


print "Location: exit;

}

# Email Body

$body_form_email = "title: $title\n"
. "name: $name\n"
. "surname: $surname\n"
. "email: $email\n"
. "message: $message\n"
. "\n"
. "";

# Send the email to the form owner

open(MAIL,"|$mailprog");
print MAIL "To: nick barker <nickbarker\@mac.com>\n";
print MAIL "From: $email\n";
print MAIL "Subject: Queries\n\n";
print MAIL $body_form_email;
close(MAIL);
# Redirect user to OK page

print "Location: exit;
# End of Perl script
 
Is the location of $mailprog the same on both servers?
Keith
 
Code:
#!/usr/bin/perl

[b][red]print "Content-type: html\n\n";[/red][/b]

$mailprog = '/usr/sbin/sendmail -t';


Kind Regards
Duncan
 
On the other server it is specified by the host as

/usr/sbin/sendmail -i -t

but I by mistake put /usr/sbin/sendmail -t

but anyway that worked too, but neither work on this server other than /usr/sbin/sendmail -t gets me to the "success" page instead of "Internal Server Error", but still no emails
 
Hi Duncan
I added your "red" code to the script
It shows the "success" url in the browser window as opposed to the actual "success" page

Hope I didn't miss your point

Still no emails
 
Try this:

Code:
#!/usr/bin/perl

use CGI qw(param);
use CGI qw(:standard);
use CGI::Carp qw(fatalsToBrowser);

my $mailprog = '/usr/sbin/sendmail';

my $title = param("title");
my $name = param("name");
my $surname = param("surname");
my $email = param("email");
my $message = param("message");
my $recipient = 'nickbarker\@mac.com';

# [COLOR=red]this next bit will never fire - $validationfailed is never defined or initialized[/color]

[COLOR=blue]if ($validationfailed == 1)
{

 print "Location: [URL unfurl="true"]http://bellevuevilla-orlando.com/office/error.html\n\n";[/URL]
 exit;

}[/color]

# Email Body

my $body_form_email = "title: $title\n"
 . "name: $name\n"
 . "surname: $surname\n"
 . "email: $email\n"
 . "message: $message\n"
 . "\n"
 . "";

# Send the email to the form owner

open MAIL, "| $mailprog -t -i" or die "Couldn't open Mail Program: $!";
print MAIL "To: $recipient\n";
print MAIL "From: $email\n";
print MAIL "Subject: Queries\n\n";
print MAIL $body_form_email;
close(MAIL);
# Redirect user to OK page

 print "Location: [URL unfurl="true"]http://bellevuevilla-orlando.com/office/success.html\n\n";[/URL]
 exit;
# End of Perl script

If this doesn't work then your host doesn't allow direct access to sendmail or the path to sendmail is incorrect. Notice the my before each variable declaration. It's good perl programming practice to do this. Also, I put your email address in a $recipient variable - I think that's where the problem lies. One more thing, I added a die statement at the open MAIL line - this will return any errors if the script can't open sendmail.

Ah, one last thing, I changed the way you're parsing the form fields. The CGI param() statement is so much easier than parsing hash/value pairs.

There's always a better way. The fun is trying to find it!
 
Have a look at Net::SMTP, as its not as prone to much of the cr3p3 that Sendmail chucks - also it's portable

Just my €0.02c
--Paul

It's important in life to always strike a happy medium, so if you see someone with a crystal ball, and a smile on their face ...
 
Hi tviman

Tried your script - thanks

error reads

malformed header from script. Bad header=nickbarker\@mac.com... User un:
 
try changing the line to this:-

[tt]print MAIL "To: nickbarker\@mac.com\n";[/tt]


Kind Regards
Duncan
 
Duncan - thanks

I tried it and I get the "success" page but do not receive the email
 
Are you certain that you have access to sendmail? I just ran into this problem last week where a well known hosting company denied access to sendmail in an attempt to ward off spammers. I had to write several emails to their tech support before they told me that I couldn't create my own custom email forms and instead, had to use their form.



There's always a better way. The fun is trying to find it!
 
I was beginning to think along the same lines.
There is no mention of the host providing forms on their site but is it a likely scenario where the recipient has to be the site owner?
 
Net::SMTP, and relay off a mail server you can access

--Paul

It's important in life to always strike a happy medium, so if you see someone with a crystal ball, and a smile on their face ...
 
The hosting company I dealt with last week didn't provide the form, you just had to pass your form through their script. It did all the parsing for you and sent the email. This precluded you from using things like CC & BCC, as well as sending more than one email at a time.

Check with the hosting company.

There's always a better way. The fun is trying to find it!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top