CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Need a Custom or Prewritten Perl Program?: I Need a Programmer for Freelance Work:
nt 200 server help

 



statpac
stranger

Aug 24, 2001, 1:54 PM

Post #1 of 7 (5696 views)
nt 200 server help Quote | Reply | Private Reply

I have written a 200 line perl script that works fine on a unix server but does not work on a Windows 2000 server. It takes data from an html form and sends mail and saves data in a file. I can provide the script on request to help you estimate the job.

Thanks.

David Walonick




Jasmine
Administrator / Moderator

Aug 25, 2001, 2:07 PM

Post #2 of 7 (5689 views)
Re: nt 200 server help [In reply to] Quote | Reply | Private Reply

What error (if any) does the script yield in Win?



statpac
stranger

Aug 26, 2001, 11:04 AM

Post #3 of 7 (5684 views)
Re: nt 200 server help [In reply to] Quote | Reply | Private Reply

Hi,

Thanks for your response.

When the submit button is clicked. It runs for a long
time and finally returns an error message:
CGI Error
The specified CGI application misbehaved by not returning a complete set of HTTP headers. The headers it did return are:
Can't call method "mail" on an undefined value at C:\Inetpub\wwwroot\cgi-bin\statpac.pl line 84.

Line 84 is $smtp->mail($from);

David



Jasmine
Administrator / Moderator

Aug 26, 2001, 10:23 PM

Post #4 of 7 (5680 views)
Re: nt 200 server help [In reply to] Quote | Reply | Private Reply

Was $smtp initialized?

Please either attach or post the code so it can be debugged.



statpac
stranger

Aug 27, 2001, 2:01 AM

Post #5 of 7 (5678 views)
Re: nt 200 server help [In reply to] Quote | Reply | Private Reply

HI,

My client did set a value for $SMTPMailServer = 'her.sever.com';

My first thought was that the SMTP module was not installed, so I asked her to install it. She said she got a message that the module was already installed.

Thanks,

David




mhx
Enthusiast

Aug 27, 2001, 2:43 AM

Post #6 of 7 (5676 views)
Re: nt 200 server help [In reply to] Quote | Reply | Private Reply

Please post your code.
It's nice to see $SMTPMailServer is set to something, but the question was if $smtp was initialized correctly. The error you got

In Reply To
Can't call method "mail" on an undefined value at C:\Inetpub\wwwroot\cgi-bin\statpac.pl line 84.

Line 84 is $smtp->mail($from);

refers to the $smtp object. It seems that $smtp has either not been initialized at all or the initialization went wrong. Net::SMTP states that failure of a method call (such as new) is indicated by returning an undefined or empty list value. In case of the constructor, this would mean that $smtp would have been assigned an undefined value instead of a blessed object reference. Looking at the source of Net::SMTP::new, I can see a lot of reasons why the constructor could return undef.
But without seeing your code, all this is pure speculation.

-- Marcus


Code
s$$ab21b8d15c3d97bd6317286d$;$"=547269736;split'i',join$,,map{chr(($*+= 
($">>=1)&1?-hex:hex)+0140)}/./g;$"=chr$";s;.;\u$&;for@_[0,2];print"@_,"



statpac
stranger

Aug 28, 2001, 3:40 AM

Post #7 of 7 (5671 views)
Re: nt 200 server help [In reply to] Quote | Reply | Private Reply

Thanks Marcus.

Here is the code. Near the beginning of the code, they define:

$SMTPMailServer = 'wwwsvr.theirdomain.org';

When I try this same code on our unix mail server, it runs perfectly. So I must be missing something exclusive to NT.

One more note: My client just installed Perl for this script, so it could be their installation or it could be my code. Unfortunately, I don't have access to their server.

Thanks again.

David


#!/usr/local/bin/perl
# Point the previous line to the location of Perl on your server
# On NT the first line would be something like #!e:\Perl\bin\Perl.exe

# There are two ways to set the email method

# Method 1 - Use with Unix servers and some NT servers
# Set the $mailprog variable to point to the mail system on your server.
# If you are on a unix server, it is probably correct.
# Sendmail, mail, and qmail are the most common. Your ISP should
# be able # to give you the path and name of your server mailing program.
# You only need to set the next line if you use Method 1.

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


# Method 2 - Use this on NT servers that do not have a sendmail program.
# You must have the perl module Net::SMTP installed on your server.
# Set the part between the single quotes to the SMTP mail host name.
# An example would be: $SMTPMailServer = 'mailhost.server.com';
# If you are using Method 1, there should be nothing between the quotes.

$SMTPMailServer = '';

# If Blat is used then set the path to Blat.exe & specify a temporary
# file name. If Blat is not being used, leave both variables blank.
# Example: $blatpathname = "e:\blat\blat.exe";
# Example: $tempfilename = "e:\inetpub\vs20\cgi-bin\blat\mailtemp$$";
$blatpathname = '';
$tempfilename = '';


# After uploading this file to your server you MUST set the permissions.
# Set the permissions for User to Read, Write and Execute (numeric code 700).


#---------------------------------------------
# ------- End of User Setup Variables --------
#---------------------------------------------

# Read the data from the form
read(STDIN, $frmdat, $ENV{'CONTENT_LENGTH'});

# Split the data into its parts.
@namval = sort(split(/&/,$frmdat));
foreach (@namval) {
tr/+/ /;
s/=/ = /;
s/%(..)/pack("C",hex($1))/ge;
($nam, $val) = split(/ = /,$_,2);
$dat{$nam} = $val;
}

# --------- Read the variables passed from the form ---------

# Get the email address where the data from the form should be sent
$email = $dat{'recipient'};

# Get the subject line for the emails (same as codebook name)
$studyname = $dat{'studyname'};

# URL of the next page
# if url = the word "default" then then next page is an automatic thankyoupage
$nextpage = $dat{'nextpage'};

# Form processing method: email or file
$method = $dat{'method'};

# Location of directory when responses are saved to a file
$storagepath = $dat{'directory'};

# If the url has a ?xxxxx then the respondent ID already exists
# Otherwise, create a new respondent ID
$Fullurl = "$ENV{'HTTP_REFERER'}";
$Position = index($Fullurl,"?");
if ($Position > 0) {
$respondentID = substr($Fullurl,$Position+1);
# also remove bookmark if necessary
$Position = index($respondentID,"#");
if ($Position > 0) {
$respondentID = substr($respondentID,0,$Position);
}
} else {
$respondentID = int(100 + rand 99999899);
}

# --------- Use Mail Program to Send Mail Now ----------

if ($method eq 'email') {

&process_form;

if ($SMTPMailServer eq '') {

open(MAILOUT, "| $mailprog $email") ||
&showerror("Cannot start mail program:","$storagepath $email");
print MAILOUT "Subject: $studyname\n\n";
# For each form field, print the form field and value.
foreach $field (@Field_Order) {
print MAILOUT "$field: $Form{$field}\n";
}
# Print blank line after each form
print MAILOUT "\n";
close(MAILOUT);

} else {

if ($blatpathname eq '') {

use Net::SMTP;
$smtp = Net::SMTP->new($SMTPMailServer);
$from = $email;
# You can change the From email address to anything here (leave the \ before the @)
# $from = "surveys\@yourdomain.com";
$subject = $studyname;
# You can change the subject line to anything you want here
# $subject = "Type any subject line here";
$smtp->mail($from);
$smtp->to($email);
$smtp->data();
$smtp->datasend("To: ", $email, "\n");
$smtp->datasend("Subject: ", $subject, "\n");
$smtp->datasend("\n");
foreach $field (@Field_Order) {
$smtp->datasend("$field: $Form{$field}\n");
}
$smtp->dataend();
$smtp->quit;

} else {

# Blat is being used
open(outfile,">$tempfilename");
foreach $field (@Field_Order) {
print outfile "$field: $Form{$field}\n";
}
print outfile "\n";
close(outfile);
system("$blatpathname $tempfilename -s $subject -t $email -server $SMTPMailServer -f $email");
}

}

# --------- Save Response to a File on the Server -----------

} elsif ($method eq 'file') {

# Name the output file the same as the codebook.asc
srand;
$storagefilename = $studyname;
$storagefilename =~ s/\W/_/g;
$outputfile = "$storagepath"."$storagefilename".".asc";

# open(MAILOUT,">>$outputfile");
# flock MAILOUT,2;
# if (-e $storagepath) {

while ((!open(MAILOUT,">>$outputfile")) && ($counter < 100))
{
$counter = $counter + 1;
}

if (not(-e $storagepath)) {
&showerror("Incorrect path:","$storagepath");
} elsif ($counter < 100) {

# Begin header with the user's IP address
$responseID = "$ENV{'REMOTE_ADDR'}";

# End header with date
@days = ('Sunday','Monday','Tuesday','Wednesday',
'Thursday','Friday','Saturday');
@months = ('January','February','March','April','May','June','July',
'August','September','October','November','December');
($sec,$min,$hour,$mday,$mon,$year,$wday) = (localtime(time))[0,1,2,3,4,5,6];
$time = sprintf("d:d:d",$hour,$min,$sec);
$year += 1900;
$date = "$days[$wday], $months[$mon] $mday, $year at $time";

&process_form;

# Begin header with the user's IP address
# First line of the email header follows
print MAILOUT "StatPac_ID: "."$responseID\n";

# Second line of the email header follows
print MAILOUT "Respondent_ID: "."$respondentID\n";

# Last line of the email header follows
print MAILOUT "Date_Time: "."$date\n";

# For each form field, print the form field and value.
foreach $field (@Field_Order) {
print MAILOUT "$field: $Form{$field}\n";
}
# Print blank line after each form
print MAILOUT "\n";

close(MAILOUT);


} else {
print "Content-type: text/html\n\n";
print "<HTML>";
print "<HEAD>";
print "<TITLE> $studyname </TITLE>";
print "</HEAD>";
print "<BODY BGCOLOR=\"#FFFFFF\">";
print "<FONT SIZE=\"5\" COLOR=\"#000000\" FACE=\"Arial\">";
print "<FORM>";
print "<CENTER>";
print "<B>The server is busy.</B><BR>";
print "Please press the Back button on your browser and try again.";
print "</CENTER>";
print "</FORM>";
print "</FONT>";
print "</BODY>";
print "</HTML>";
close(STDOUT);
exit 0;
}


# -------------------- Goofy Method Specified -------------------
} else {

&showerror("Not a valid method:","$method");

}

# -------------------- Create Default Thank You File -------------------

if ($nextpage eq "default") {
print "Content-type: text/html\n\n";
print "<HTML>";
print "<HEAD>";
print "<TITLE> $studyname </TITLE>";
print "</HEAD>";
print "<BODY BGCOLOR=\"#FFFFFF\">";
print "<FONT SIZE=\"5\" COLOR=\"#000000\" FACE=\"Arial\">";
print "<FORM>";
print "<CENTER>";
print "<B>Thank you for completing this survey.</B><BR><BR>";
print "Your response has been received.";
print "</CENTER>";
print "</FORM>";
print "</FONT>";
print "</BODY>";
print "</HTML>";


# -------------------- Show The Next Page -------------------

} else {

# if nextpage has a bookmark, put the bookmark on the end of the page link

$bookmark='';
$Position = index($nextpage,"#");
if ($Position > 0) {
$bookmark = substr($nextpage,$Position+1);
$nextpage = substr($nextpage,0,$Position);
}
$finalurl = $nextpage."?".$respondentID;
if ($bookmark ne '') {
$finalurl = $finalurl."#".$bookmark;
}
print "Location: $finalurl\n\n";
}
close(STDOUT);

# -------------------- Show A Perl Script Error -------------------

sub showerror {
print "Content-type: text/html\n\n";
print "<HTML>";
print "<HEAD>";
print "<TITLE> $studyname </TITLE>";
print "</HEAD>";
print "<BODY BGCOLOR=\"#FFFFFF\">";
print "<FONT SIZE=\"6\" COLOR=\"#000000\" FACE=\"Arial\">";
print "<FORM>";
print "<CENTER>";
print "<B>Error in the perl script:</B><BR>";
print "</FONT>";
print "<FONT SIZE=\"5\" COLOR=\"#000000\" FACE=\"Arial\">";
print "<B><I>$ENV{'SCRIPT_FILENAME'}</B></I><BR><BR>";
print "</FONT>";
print "<FONT SIZE=\"4\" COLOR=\"#000000\" FACE=\"Arial\">";
foreach (@_) {
print "$_<BR>";
}
print "</CENTER>";
print "</FORM>";
print "</FONT>";
print "</BODY>";
print "</HTML>";
close(STDOUT);
exit 0;
}

sub process_form {

# Define the configuration array for special fields
%Config = ('recipient','', 'method','',
'directory','', 'studyname','',
'nextpage','');

# What is the form's REQUEST_METHOD (GET or POST)
if ($ENV{'REQUEST_METHOD'} eq 'GET') {
# Split the name-value pairs
@pairs = split(/&/, $ENV{'QUERY_STRING'});
}
elsif ($ENV{'REQUEST_METHOD'} eq 'POST') {
$buffer = $frmdat;
# Split the name-value pairs
@pairs = split(/&/, $buffer);
}
else {
&error('request_method');
}

# Do for each name-value pair
foreach $pair (@pairs) {

# Split up the pair
local($name, $value) = split(/=/, $pair);

# Decode the form encoding
$name =~ tr/+/ /;
$name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;

$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;

# Erase any server side includes
$value =~ s///g;

# Erase any embedded carriage returns, tabs, line feed, & form feed characters
$value =~ s/[\r\t\n\f]/ /g;

# Put special field names in the %Config array & others in the %Form array
# Save the order of the form fields in the @Field_Order array
if (defined($Config{$name})) {
$Config{$name} = $value;
}
else {
if ($Form{$name} && $value) {
$Form{$name} = "$Form{$name}, $value";
}
elsif ($value) {
push(@Field_Order,$name);
$Form{$name} = $value;
}
}
}
}



 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives