Forum Moderators: coopster & phranque

Message Too Old, No Replies

Help with a simple cgi form script

this is killing me

         

Adam_C

8:25 pm on Jan 23, 2003 (gmt 0)

10+ Year Member



I'm trying to add a form to one of my sites, and its proving to be a nightmare. Delving into areas I don't fully understand here, so if anyone can sort this out for me I'll be eternally greatful.

This is the script I'm using:

#!/usr/bin/perl

$sendmail = "/usr/lib/sendmail"; # Where is sendmail?
$to = "me\@mydomain.com"; # Who is going to receive the mail.
$from = "form\@mydomain.com"; # From who the mail is sended.
$subject = "Mail"; # The Mail's Subject.
$location = "http://www.mydomain.com"; # The page to be redirect after the mail was sended.
###
# Rest of the "Escri"

read(STDIN, $namevalues, $ENV{'CONTENT_LENGTH'});

open (MAIL, "¦$sendmail $to") ¦¦ die "Can't open $sendmail!\n";
print MAIL ("To: $to\n");
print MAIL ("From: $from\n");
print MAIL ("Subject: $subject\n\n");

# Process info from Fill in Form

@namevalues = split(/&/, $namevalues);
foreach $namevalue (@namevalues) {
($name, $value) = split(/=/, $namevalue);
$name =~ tr/+/ /;
$value =~ tr/+/ /;
$name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$INPUT{$name} = $value;
unless ($value eq "") {
print MAIL ("$name: $value\n");
}
}

close (MAIL);

print ("Location: $location\n");

exit;

The mail is sending, however I'm getting an error 500 message rather than redirecting to [mydomain.com....]

I've set chmod to 755 and i'm ftp-ing in ASCII.

My error log gives the following:

Premature end of script headers: /home/httpd/vhosts/mydomain.com/cgi-bin/form.cgi

jeremy goodrich

8:40 pm on Jan 23, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



print "Location: $somesite\n\n";

2 new lines at the end of that script should do it. :)

Let us know if that works.

Adam_C

8:48 pm on Jan 23, 2003 (gmt 0)

10+ Year Member



let me get this right....

just add

print "Location: $somesite\n\n";

to the bottom of the script, after

exit;

Surely thats only 1 new line?

Key_Master

8:51 pm on Jan 23, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Change $sendmail = "/usr/lib/sendmail"; # Where is sendmail? to:
$sendmail = "/usr/lib/sendmail -t"; # Where is sendmail?

Change open (MAIL, "¦$sendmail $to") ¦¦ die "Can't open $sendmail!\n"; to:
open (MAIL, "¦$sendmail") ¦¦ die "Can't open $sendmail!\n";

Change print ("Location: $location\n"); to:
print ("Location: $location\n\n");

jatar_k

8:52 pm on Jan 23, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



jeremy, I would think, is referring to change this

print ("Location: $location\n");

from your script

to this

print ("Location: $somesite\n\n");

the 2 newlines being "\n\n"

<added>Key_Master was quicker ;)

Adam_C

9:06 pm on Jan 23, 2003 (gmt 0)

10+ Year Member



Thanks for all your input guys. I've managed to sort it by changing

$location = "http://www.mydomain.com"; # The page to be redirect after the mail was sended.

to

$somesite = "http://www.mydomain.com"; # The page to be redirect after the mail was sended.

and

print ("Location: $location\n");

to

print ("Location: $somesite\n\n");