Re: [Exim] Exim under Debian Woody v3.0r1 to send forms from…

Páxina inicial
Borrar esta mensaxe
Responder a esta mensaxe
Autor: Luke Pascoe
Data:  
Para: Nestor R. Mazza, Debian exim-users
Asunto: Re: [Exim] Exim under Debian Woody v3.0r1 to send forms from website
Slap the following in a file and make it executable, important fields are
listed at the top (inside the param("...")) you can specify which ones are
required with the "special_required" field. The script will forward them to
"special_forward" when it's sent. You should be able to figure the rest out
yourself :-)

BTW, this works for any mail program that has a sendmail wrapper.

=== From here on: ===
#! /usr/bin/perl -w

use CGI;
use strict;
my $cgi = new CGI;

die "Mailto address not specified" unless
(defined($cgi->param("special_mailto")));
my $subject = $cgi->param("special_subject") || "Form2Mail script output";
my $forward = $cgi->param("special_forward") || "";
my $reply = $cgi->param("special_reply") || "";
my $bgcolor = $cgi->param("special_bgcolor") || "FFFFFF";
my $textcolor = $cgi->param("special_textcolor") || "000000";
my $required = $cgi->param("special_required") || "";

# Check for required fields
if ($required ne "")
{
        my $field;
        foreach $field (split(/,/, $required))
        {
                if (($field ne "") && ((! defined($cgi->param($field))) ||
($cgi->param($field) eq "")))
                {
                        print <<EOM;
<html>
<head>
        <title>Form Error</title>
</head>
<body bgcolor="#$bgcolor" text="#$textcolor" link="#$textcolor"
vlink="#$textcolor">
        Required field missing: $field
</body>
</html>
EOM
                        exit;
                }
        }
}


open(SENDMAIL, "|/usr/sbin/sendmail -t") || die "Couldn't open SENDMAIL:
$!";
print SENDMAIL "To: ", $cgi->param("special_mailto"), "\n";
print SENDMAIL "Reply-To: $reply\n" if ($reply ne "");
print SENDMAIL "Subject: $subject\n\n";
foreach (sort $cgi->param)
{
        if (! ($_ =~ /^special_/i))
        {
                print SENDMAIL "$_ = " . join(", ", $cgi->param("$_")) .
"\n";
        }
}
print SENDMAIL "\n.\n";
close SENDMAIL;


if ($forward ne "")
{
        print <<EOM;
<html>
<head>
        <META HTTP-EQUIV=Refresh CONTENT=\"0; URL=$forward\">
</head>
<body bgcolor="#$bgcolor" text="#$textcolor" link="#$textcolor"
vlink="#$textcolor">
        You should be forwarded to $forward. If not, <a
href=\"$forward\">click here</a>
</body>
</html>
EOM
}
else
{
        print <<EOM;
<html>
<body bgcolor="#$bgcolor" text="#$textcolor" link="#$textcolor"
vlink="#$textcolor">
        Form submitted, Please press the back button on your browser to
return to where you were.
</body>
</html>
EOM
}