GamerDude3282
04-28-2010, 01:56 AM
I'm just starting out with CGI..
And my assignment was to create an e-mail form utilizing CGI and perl and forms.
I keep getting this error: Undefined subroutine &main:: param called at ./a16.cgi line 26
I've looked at it for several hours, and still can't figure out why it won't work. My instructor also couldn't figure out why.
I don't think its recognizing "param" as a function, your help would be very much appreciated!
CGI code:
#!/usr/bin/perl -w
use warnings;
use strict;
use CGI::Carp qw/fatalsToBrowser/;
use Mail::Sendmail;
print "Content-Type: text/html\n\n";
# use your address here instead of me@somewhere.com for testing purposes!
my $mailTo = param('to');
# use your address here instead of me@nowhere.com for testing
my $mailFrom = param('from'); # in your CGI, this will be val of param()
my $subjectLine = param('subject'); # in your CGI, this will be val of param()
my $message = param('message'); # in your CGI, this will be val of param()
if ($mailTo eq "")
{
print "Please enter your e-mail address!"
}
if ($mailFrom eq "")
{
print "<br/>Please enter recipient's e-mail address!"
}
if ($subjectLine eq "")
{
print "<br/>Please enter subject!"
}
if ($message eq "")
{
print "<br/>Please enter a message!"
}
#if ($mailTo or $mailFrom or $subjectLine or $message eq "")
#{
#print a ({ -href => "javascript:history.back();" }, "Go back and fill in everything!");
#}
my %mail = ( To => $mailTo,
From => $mailFrom,
Subject => $subjectLine,
Message => $message, # must be a string, not an array
'Content-Type' => 'text/plain'
);
if ($mailTo and $mailFrom and $subjectLine and $message ne "")
{
(sendmail %mail ) and
print "Successfully sent mail to $mailTo. Check your box!\n";
}
Form code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Mail-Me Program</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="my.css" />
</head>
<body>
<form name="mailme" action="a16.cgi" method="get">
Enter your e-mail address:
<br/><input type="text" name="from" />
<br/>Enter recipient's e-mail:
<br/><input type="text" name="to" />
<br/>Enter a subject:
<br/><input type="text" name="subject" />
<br/>Enter your message:
<br/><textarea name= "message" rows="10" cols="50"></textarea>
<br/><input type="submit" value="Submit!" />
<input type="reset" value="Reset!" />
</form>
<p><a href="http://validator.w3.org/check?uri=referer"><img
src="http://www.w3.org/Icons/valid-xhtml10-blue"
alt="Valid XHTML 1.0 Tansitional" height="31" width="88" /></a>
</p>
</body>
</html>
And my assignment was to create an e-mail form utilizing CGI and perl and forms.
I keep getting this error: Undefined subroutine &main:: param called at ./a16.cgi line 26
I've looked at it for several hours, and still can't figure out why it won't work. My instructor also couldn't figure out why.
I don't think its recognizing "param" as a function, your help would be very much appreciated!
CGI code:
#!/usr/bin/perl -w
use warnings;
use strict;
use CGI::Carp qw/fatalsToBrowser/;
use Mail::Sendmail;
print "Content-Type: text/html\n\n";
# use your address here instead of me@somewhere.com for testing purposes!
my $mailTo = param('to');
# use your address here instead of me@nowhere.com for testing
my $mailFrom = param('from'); # in your CGI, this will be val of param()
my $subjectLine = param('subject'); # in your CGI, this will be val of param()
my $message = param('message'); # in your CGI, this will be val of param()
if ($mailTo eq "")
{
print "Please enter your e-mail address!"
}
if ($mailFrom eq "")
{
print "<br/>Please enter recipient's e-mail address!"
}
if ($subjectLine eq "")
{
print "<br/>Please enter subject!"
}
if ($message eq "")
{
print "<br/>Please enter a message!"
}
#if ($mailTo or $mailFrom or $subjectLine or $message eq "")
#{
#print a ({ -href => "javascript:history.back();" }, "Go back and fill in everything!");
#}
my %mail = ( To => $mailTo,
From => $mailFrom,
Subject => $subjectLine,
Message => $message, # must be a string, not an array
'Content-Type' => 'text/plain'
);
if ($mailTo and $mailFrom and $subjectLine and $message ne "")
{
(sendmail %mail ) and
print "Successfully sent mail to $mailTo. Check your box!\n";
}
Form code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Mail-Me Program</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="my.css" />
</head>
<body>
<form name="mailme" action="a16.cgi" method="get">
Enter your e-mail address:
<br/><input type="text" name="from" />
<br/>Enter recipient's e-mail:
<br/><input type="text" name="to" />
<br/>Enter a subject:
<br/><input type="text" name="subject" />
<br/>Enter your message:
<br/><textarea name= "message" rows="10" cols="50"></textarea>
<br/><input type="submit" value="Submit!" />
<input type="reset" value="Reset!" />
</form>
<p><a href="http://validator.w3.org/check?uri=referer"><img
src="http://www.w3.org/Icons/valid-xhtml10-blue"
alt="Valid XHTML 1.0 Tansitional" height="31" width="88" /></a>
</p>
</body>
</html>