develooper Front page | perl.beginners | Postings from January 2002

How to change perl form-processing script for Windows NT server?

Thread Next
Rohesia Hamilton
January 9, 2002 13:30
How to change perl form-processing script for Windows NT server?
Message ID:

I have recently finished my first perl script, which
processes a form, returns an html thank you page to
the submitter, sends them a confirmation email, sends
the company (whose website the form is for) an email
and appends the contents of the form to a text file. 

I used my UNIX account as I put the script together
(easy to debug) and it works perfectly from there.

Where it is supposed to go, however, is on a Windows
NT server, so I've moved it there to try. The html
page is returned perfectly (suggesting to the
submitter that all is well, thank you) but no emails
get sent and (as far as I can tell) no text file gets
created (in my original, the text file created itself
right in the cgi-bin -- as I could access it fine, I
left it there).

I am pasting an abbreviated version of the script
below (nothing vital to its working is deleted). I
have heard from the system administrator that where I
originally used sendmail, I will need to use SMPT, so
I have substituted SMPT where I had the sendmail
reference. It didn't make any difference. 

Is it just a question of some directory structures
that I don't know (I haven't been able to reach the
system administrator yesterday or today) or is there
something major that I have to change here?

Many thanks in advance for any help.

Rohesia Hamilton Metcalfe

Here's the script:


use CGI qw(:standard); 			# import shortcuts
use Fcntl qw(:flock);           # imports LOCK_EX,

# The basic info from the form submission:            
$FirstName = param('FirstName');
$LastName = param('LastName');
$OtherFields = param('OtherFields');                  
$Email = param('Email');

# Putting all this information into one long string
for input into text file:
$EndRecord = "\n";
@AllData = ($LastName, $FirstName, $OtherFields,
$Email, $EndRecord);
$AllData = join (":", @AllData);

# Setting up to send an email to the person who
submitted the form with a cc to x-person
$emailProgram   = "| /usr/sbin/sendmail -oi -t";
$emailRecipient = $Email;
$emailAdmin = "x-person\";     # cc to
$emailSender = "x-person\";
$emailSubject = "X-Company Submission Info - PLEASE

# Creating a message based on the information in the
$message  = "Dear $FirstName $LastName,\n\n
Thank you for the information you have just

The information you submitted is as follows:\n
First Name: $FirstName\n
Family Name: $LastName\n
Other Fields: $OtherFields\n
E-mail: $Email\n


# Sending the email:

$errmsg = &SendMessage (
    'to'       => $emailRecipient,
    'cc'	   => $emailAdmin,
    'from'     => $emailSender,
    'subject'  => $emailSubject,
    'message'  => $message,

# Sending an html response back to whoever filled out
the form:
if ($errmsg eq 'sent')
    print <<STOP_PRINT;
Content-type: text/html

<title>Thank You!</title>
<body bgcolor="#ffffff" text="#000000">

<p><font size="+1">
Thank you <B>$FirstName $LastName.</B></p>
In the meantime, here is a listing of the information
you submitted.

First Name: <B>$FirstName</B><BR>
Family Name: <B>$LastName</B><BR>
Other Fields: <B>$OtherFields</B><BR>
E-mail: <B>$Email</B><BR>


    print <<STOP_PRINT;
Content-type: text/html

<body bgcolor="#ffffff" text="#000000">

<p><font size="+1" color="#0000ff">
I encountered an error trying to process your


# Sending the info to textfile, "x-filename.txt"


#   A routine to handle interaction with sendmail. 

sub SendMessage
    my (%args) = @_;

    if (not $args{from})    { return "No 'from'
header."; }
    if (not $args{to})      { return "Please go back
and enter your email address"; }
    if (not $args{subject}) { return "No 'subject'
header."; }

    if (open SENDMAIL, $emailProgram)
        print SENDMAIL "From: $args{from}\n";

        if ($args{'reply-to'})
        { print SENDMAIL "Reply-to: ",
$args{'reply-to'}, "\n"; }

        print SENDMAIL "To: $args{to}\n";

        if ($args{cc})
        { print SENDMAIL "Cc: $args{cc}\n"; }

        print SENDMAIL "Subject: $args{subject}\n";
        print SENDMAIL "\n";
        print SENDMAIL $args{message};
        print SENDMAIL "\n";

        close SENDMAIL;
        return "sent";
    else { return "Can't launch sendmail."; }

# a routine to output the submitted data to a file

sub DataEntry
open (X-FILE, ">>x-filename.txt") || die "can't open
x-filename.txt: $! ";
flock (X-FILE, LOCK_EX) || bail ("cannot flock
x-filename.txt: $!");

print X-FILE $AllData;

close (X-FILE) || die "couldn't close x-filename.txt:

Do You Yahoo!?
Send FREE video emails in Yahoo! Mail!

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About