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
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");
$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");