Här är perl-koden:
$sendmethod = 'libnet'; # Sändmetod "libnet" / "sendmail".
$mailprog = '/usr/lib/sendmail'; # Om du använder sendmail anger du sökvägen
# till programmet sendmail här.
$mailserver = 'smtp.glidecom.se'; # Mailserveradress.
$allow_recipient_from_form = '1'; # '0'(nej) eller '1'(ja).
$recipient = 'your_email@domain.com'; # Mottagarens e-postadress.
$allow_sender_from_form = '1'; # '0'(nej) eller '1'(ja).
$sender = ''; # Adress som skall stå som avsändare.
$allow_replyto_from_form = '0'; # '0'(nej) eller '1'(ja).
$replyto = ''; # Adress dit svarsmail skall skickas. Får samma
# värde som $senter om den lämnas tom.
$use_template = '1'; # '0'(nej) eller '1'(ja).
$allow_template_from_form = '0'; # '0'(nej) eller '1'(ja).
$templatefile = 'template.txt'; # Templatefil som skall användas.
$basedir = 'http://www.hakansdansskola.se/cgi-bin/'; # Sökväg till den katalog där berörda filer ligger.
$default_subject = 'E-post från puruff'; # Det som skall stå som ämne om inget annat anges.
$allow_redirect_from_form = '0'; # '0'(nej) eller '1'(ja).
$redirect = 'http://www.hakansdansskola.se/wap/index.wml'; # URL till ev. tacksida.
# Ändra inte på följande rader.
if(lc($sendmethod) eq "libnet"){
use Net::SMTP;
}
&init;
&read_form;
if($form{'jxsubject'}){
$default_subject = $form{'jxsubject'};
}
if($allow_recipient_from_form eq "1" && $form{'jxrecipient'}){
$recipient = $form{'jxrecipient'};
}
if($allow_sender_from_form eq "1" && $form{'jxsender'}){
$sender = $form{'jxsender'};
}
if($allow_replyto_from_form eq "1" && $form{'jxreplyto'}){
$replyto = $form{'jxreplyto'};
}
if($allow_template_from_form eq "1" && $form{'jxtemplatefile'}){
$templatefile = $form{'jxtemplatefile'};
}
if($allow_redirect_from_form eq "1" && $form{'jxredirect'}){
$redirect = $form{'jxredirect'};
}
if (length($replyto) < 1){
$replyto = $sender;
}
if($use_template eq "1"){
open(INDATA,$basedir . "/" . $templatefile);
@maillines = <INDATA>;
close(INDATA);
$maillines[0] = "\n" . $maillines[0];
for($n=0;$n<=$#maillines;$n++){
if ($maillines[$n] =~ /%%(.*)%%/) {
foreach $testmacro (@macros){
$maillines[$n] =~ s/%%$testmacro%%/$form{$testmacro}/g;
}
$maillines[$n] =~s/%%date%%/$date/g;
$maillines[$n] =~s/%%clock%%/$clock/g;
$maillines[$n] =~s/%%userip%%/$ENV{'REMOTE_ADDR'}/g;
}
}
} else {
@maillines = ("\n");
foreach $testmacro (@macros){
push(@maillines, $testmacro . " : " . $form{$testmacro} . "\n");
}
}
&send_mail;
if ($redirect){
print "Location: $redirect\n\n";
} else {
print "Content-type: text/html\n\n";
print <<End_of_html;
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Meddelandet skickat</title>
</head>
<body bgcolor="white">
<h3>Tack!</h3>
Ditt meddelande är skickat.<br>
<a href="$ENV{'HTTP_REFERER'}">Tillbaks</a>
</body>
</html>
End_of_html
}
sub send_mail {
if ($sendmethod eq "sendmail"){
my $mailmsg = <<End_of_mail;
To: $recipient
From: $sender
Reply-to: $replyto
Content-type: text/plain; charset=ISO-8859-1
Subject: $default_subject
End_of_mail
foreach $mailline (@maillines){
$mailmsg .= $mailline;
}
open(SMTP,"|$mailprog -t");
print SMTP $mailmsg;
close(SMTP);
} elsif ($sendmethod eq "libnet"){
my $mailmsg = <<End_of_mail;
From: $sender
Reply-to: $replyto
To: $recipient
Content-type: text/plain; charset=ISO-8859-1
Subject: $default_subject
End_of_mail
foreach $mailline (@maillines){
$mailmsg .= $mailline;
}
my $smtp = Net::SMTP->new($mailserver);
$smtp->mail($sender);
$smtp->to($recipient);
$smtp->data();
$smtp->datasend($mailmsg);
$smtp->dataend();
$smtp->quit();
}
}
sub read_form {
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ s/<!--(.|\n)*-->//g;
$form{$name} = $value;
push(@macros,$name);
}
}
sub init {
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
$mon++;
$mon = substr("0" . $mon,length($mon)-1,length($mon)+1);
$mday = substr("0" . $mday,length($mday)-1,length($mday)+1);
if ($year > 99){
$year += 1900;
}
$date = $year . "-" . $mon . "-" . $mday;
$sec = substr("0" . $sec,length($sec)-1,length($sec)+1);
$min = substr("0" . $min,length($min)-1,length($min)+1);
$clock = $hour . ":" . $min . ":" . $sec;
}
Här är själva wml-scriptet:
<?xml version="1.0"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN"
"http://www.wapforum.org/DTD/wml_1.1.xml">
<wml>
<card id="E-post" title="Uppgift 22">
<p>Meddelande: <input name="mailbody"/>
Subject: <input name="jxsubject"/>
Din e-post: <input name="jxsender"/>
Mott. e-post: <input name="jxrecipient"/>
<anchor>Skicka
<go method="post" href="../cgi-bin/jxformmail.pl">
<postfield name="mailbody" value="mailbody"/>
<postfield name="jxsubject" value="jxsubject"/>
<postfield name="jxsender" value="jxsender"/>
<postfield name="jxrecipient" value="jxrecipient"/>
</go>
</anchor></p>
</card>
</wml>