How do you process a form using perl?

at the moment i am using the asp equivilant, but the webserver i am hosting with doesnt allow asp:

set objmail = server.CreateObject("CDONTS.NewMail")
objmail.from = "Web Form" = ""
objmail.Subject = "Registration"
objmail.Body =  "Email: " & request.form("Email")
set objmail = nothing

does anyone know how to convert this to perl?
Who is Participating?
ziffgoneConnect With a Mentor Commented:
Hello Jyontex,

First off, make sure you know your paths to Perl and Sendmail. Your hosting company will be able to tell you this.

Depending on the Perl Modules installed on your hosting company's server, this should be a replacement for the above ASP you posted:

Begin Code ----------------------------------------------------------------

#!/usr/bin/perl -w
# make sure the above is correct path to perl from your server and is the first line in the file.
use strict;
use CGI;
use CGI qw(:standard);
use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
# Remove the above line after all debugging is complete.


$to = "";
$from = " Web Form <>";
$reply = "";
$subject = "Registration";
$email = param('Email');
$body = "Email: ".$email;
$sendmail = "/usr/sbin/sendmail";
# Make sure the above line is the correct path to sendmail on your server.

# Now it is time to send the e-mail.
open(MAIL, "|$sendmail -t -oi") or die "Cannot open $sendmail: $!";
print MAIL "To: $to\n";
print MAIL "From: $from\n";
print MAIL "Reply-to: $reply\n";
print MAIL "Subject: $subject\n";
print MAIL "Content-type: text/plain\n\n";
print MAIL $body."\n\n";

# Email sent, redirect to Thank You page:
my $q = new CGI;
print $q->redirect( "" );

End Code ----------------------------------------------------------------

Using the "use CGI::Carp qw(warningsToBrowser fatalsToBrowser);" will tell you of any script errors and what line they occur on for debugging. Using "strict" hightens the security of the script.

Hope that helps you out.


If possible, use PHP or something like that. For Perl, if your server is Unix, you can simply use sendmail. Otherwise, you need to download other modules, or etc. For a sendmail example, something like this would work:

open(MAIL, "| /usr/lib/sendmail -t -oi") or die "Can't fork for sendmail: $!\nCould be wrong path.";

my $to = "";
my $from = "Web Form";
my $subject = "Registration";
my $body = "Email: " . param("Email");

print MAIL "To: $to";
print MAIL "From: $from";
print MAIL "Subject: $subject";
print MAIL $body;

JyontexAuthor Commented:
unfortunatly the hosting solution only allows pl for processing.  I have spoken to the people i host with and they say its a Linux server.

Also tried the script above, and get:  CGIWrap Error: Script Execution Failed  

Any idea what that could be?
Train for your Pen Testing Engineer Certification

Enroll today in this bundle of courses to gain experience in the logistics of pen testing, Linux fundamentals, vulnerability assessments, detecting live systems, and more! This series, valued at $3,000, is free for Premium members, Team Accounts, and Qualified Experts.

Make sure the script is uploaded in ascii mode and not binary.
Another note Jyontex, incase you are not familiar with such, make sure you CHMOD the file to 755.

JyontexAuthor Commented:
Thank you....that was very detailed.
No problem, my pleasure to help out.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.