Okay, only my second Perl routine written in anger. I found a
few scripts that nearly did what I wanted, but they either
didn't work, were too general, or required loads of alteration
to forms before I could use them.
I wanted something to drop in the "ACTION" statement of a form
to send a mail at the server end, without requiring loads of
parameters, sendmail, or other sins. I also wanted to use CGI
and Net:SMTP as this seems to make it all very portable, clean
and short, compared to some sample scripts.
I know it needs more error checking. I know it doesn't handle
SMTP failure cleanly.
Does it need stricter checking on the data to avoid security
issues?
Can I do anything to make navigation back easier after a message
is sent? I guess I can pick up the referrer ENV variable, and
even issue a redirect or similar, but is there a really elegant
approach, like a button or call that forces a back on all
browsers.
Simon, rashly stepping outside his area of expertise.
#!/usr/bin/perl -w
use strict;
use Net::SMTP;
use CGI;
my $query; # CGI passed data
my $smtp;
# Enter SMTP relay here
$smtp = Net::SMTP->new('smtp.uklinux.net', Timeout =>60);
# Get Query parameters from CGI
$query = new CGI;
$smtp->mail($ENV{USER});
# Enter Destination Address here
$smtp->to('[EMAIL PROTECTED]');
$smtp->data();
$smtp->datasend("To: Simon\@wretched.demon.co.uk\n");
$smtp->datasend("Subject: Web Site Submission\n");
$smtp->datasend("\n");
$smtp->datasend("Fields from Web Site Form\n");
$smtp->datasend("-------------------------\n");
my (@values,$key);
foreach $key ($query->param) {
$smtp->datasend("$key \n");
$smtp->datasend("\n");
@values = $query->param($key);
$smtp->datasend("@values \n");
$smtp->datasend("-------------------------\n");
}
$smtp->dataend();
$smtp->quit;
my $answer;
$answer = new CGI;
print $answer->header(),
$answer->start_html(-title=>'Mail Sent'),
$answer->h1('Your mail has been sent'),
'Thank you for your Interest, now pick "Back"',
$answer->end_html();
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]