|
|
Below please
find the code for the file I named mylib.lib, this file must be placed
in your cgi-bin folder on your apache server.For this file the owner
must have read, write and executable permissions and the only other
permission to be set is that the user other must have read access
|
#!/opt/bin/perl
sub Parse_Form
{
if ($ENV{'REQUEST_METHOD'} eq 'GET')
{
@pairs=split(/&/, $ENV{'QUERY_STRING'});
}
elsif ($ENV{'REQUEST_METHOD'} eq 'POST')
{
read(STDIN,$buffer,$ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
}
foreach $pair (@pairs)
{
($key,$value)=split(/=/,$pair);
$key =~ tr/+/ /;
$key=~s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
if ($formdata{$key})
{
$formdata{$key} .= ", $value";
}
else
{
$formdata{$key} = $value;
}
}
}
1; |
Below find my file I called mail.cgi as with mylib.lib it must also
be placed in your cgi-bin folder of your Apache webserver. The owner of
this code should have read, write and execute permission set and the only
other permission to be set is the user other having executable permission. |
#!/opt/bin/perl
use Net::SMTP;
use CGI qw(:standard);
push(@INC, ".");
require 'mylib.lib';
&Parse_Form;
$to = $formdata{"TO"};
$from = $formdata{"FROM"};
$subject = $formdata{"SUBJECT"};
$subject =~ s/\+/ /g;
$subject =~ s/%(..)/pack("c",hex($1))/ge;
$message = $formdata{"MESSAGE"};
$message =~ s/\+/ /g;
$message =~ s/%(..)/pack("c",hex($1))/ge;
$mailserver = $formdata{"MAILSERVER"};
$smtp = Net::SMTP->new($mailserver);
$smtp->mail($ENV{USER});
$smtp->to("$to");
$smtp->data();
$smtp->datasend("To: $to \n");
$smtp->datasend("From: $from \n");
$smtp->datasend("Subject: $subject \n");
$smtp->datasend("\n");
$smtp->datasend("$message \n");
$smtp->dataend();
$smtp->quit;
print "Content-type:text/html\n\n";
print "<\head\>\n";
print "<\title\>Email Verification<\/title\>\n";
print "<\/head\>\n";
print "<\body\>\n";
print "<\H3\>The request has been Processed.<\/H3\>\n ";
print "<\H3\>Thank You $from<\/H3\>\n";
print "<\/body\>\n";
print "<\/html\>\n";
|
NB The html section of this code may be changed to reflect a consistent look for your website. Please ignore the
\ slashes within the HTML tags, they were put in so as the HTML code would print to the page.When running the code to see
if it works, I suggest you submit an email your cs account to test it. In addition for your scripts to work
the field names in your form must correspond to the ones I used here e.g. TO, FROM, etc. Remember to name your mailserver
mail.cs.dal.ca
Good Luck with your assignments.
|
|