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

PERL Email form misbehaving.

Status
Not open for further replies.

chrigil

Programmer
Sep 23, 2003
178
GB
Can anyone see any glaring omissions/errors in this script? It was working one day and then no the next. I'm 99.9% sure it hasn't been altered and would just like someone to confirm that it is the server and not me going mad.

At the moment all it gives me is a "CGI ERROR The specified CGI application misbehaved by not returning a complete set of HTTP headers."


!/usr/bin/perl

use OLE;
use CGI;
$jmail = CreateObject OLE "JMail.SMTPMail";

$form = new CGI;
$Recipient="genuine@address.co.uk";
$name=$form->param('name');
$fromEmail=$form->param('fromEmail');
$PreBody=$form->param('body');

$Body=$PreBody."\n\n".$name;

$domain = $ENV {'SERVER_NAME'};
$referer = $ENV {'HTTP_REFERER'};
$url = $referer;
$url =~ s/^http:\/\///i;
$url =~ s/^$domain =~ s/^
$Sender = "$fromEmail";
$SMTPServer = "smtp.$domain:25";
$Subject = "Crispini Website Feedback";
$Priority=3;
$Header = "Originating-IP", $ENV{'REMOTE_ADDR'};

$jmail->{ServerAddress} = $SMTPServer;
$jmail->{Sender} = $Sender;
$jmail->{Subject} = $Subject;
$jmail->AddRecipient ($Recipient);
$jmail->{Body} = $Body;
$jmail->{Priority} = $Priority;
$jmail->AddHeader ($Header);

if ($url =~ m/^$domain/)
{
$mailmessage = "mail sent";
$jmail->Execute;
}
else
{
print "Content-type: text/html\n\n";
$mailmessage = "mail was not sent. Incorrect Referer";
}
print "location:
I have basically copied and pasted this script as I'm not a PERL programmer (Thankfully ; )

Thanks in advance,

Chris
 
From a quick glance, it looks like you're printing the header when the mail is not sent, but not printing it when the mail is sent:
Code:
if ($url =~ m/^$domain/)
{
[COLOR=red]# No header being printed here[/color]
$mailmessage = "mail sent";
$jmail->Execute;
}
else
{
[COLOR=red]# Here's the header:[/color]
print "Content-type: text/html\n\n";
$mailmessage = "mail was not sent. Incorrect Referer";
}

 
try using this in your CGI scripts as well:
Code:
use CGI::Carp qw(fatalsToBrowser);
It usually helps me debug my CGI bugs by spitting out some slightly more useful error messages on screen.

But I would agree with philote, you haven't printed the header in the first part of that 'if' statement.

Rob Waite
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top