1. "Sending Mail"'
|
Sending
Mail from within your script is non-trivial and full of traps, so be aware
that you have to know what you are doing, otherwise better leave it
!!!
|
|
There are many perl programs which rely on the
existence of the local UNIX commands like 'sendmail' ! Be aware, for
security reasons, "sendmail"
may not be available central where your site is hosted !!!
In any case always avoid relying on commands on the server but use e.g. Perl-modules
that make your program self-consitent ! |
|
|
In
any case you might want to consider using the
central Web-servers where advanced techniques like mailing forms etc can be done very easily !!!
(for more info see http://cern.ch/WebServices/AuthoringDoc/Forms/forms.htm)
|
There is a 'non-standard' Perl-Module (not
included in the standard Perl distribution) available
that you can/(have-to) download if you want to send mails from within your script
in a way without relying on mail-commands that may or may not be available on
the Web-Server handling your Web-Site ! It is called Mail::SendMail
and can be downloaded e.g. from:
http://alma.ch/perl/mail.htm
Get the Module Sendmail.pm from the address
above and put it in a folder 'Mail' where your script can find it (include it in
the lib path, ie. 'use lib "path/to/your/mail/library"). The the
following example
my $query = new CGI;
print $query->header();
my (%mail,$server,$loaded);
$mail{From} = 'Sendmail Test <mailaddress_sender@domain.name>';
$mail{To} = 'Sendmail Test <mailaddress_receiver@domain.name>';
$server = 'cernmx.cern.ch';
END {print "not ok 1\n" unless $loaded;}
use Mail::Sendmail;
$loaded = 1;
print "<b>Mail::Sendmail Loaded: ok 1\n</b><br><pre>";
print "Test Mail::Sendmail $Mail::Sendmail::VERSION\n
Here is the message text of your message\n
Current recipient(s): '$mail{To}'\n";
if ($server) {
$mail{Smtp} = $server;
print "Server set to: $server\n";
}
$mail{Subject} = "Mail::Sendmail version $Mail::Sendmail::VERSION test";
$mail{Message} = "This is a test message sent with Perl version $] from a $^O system.\n\n";
$mail{Message} .= "It was sent on " . Mail::Sendmail::time_to_date() . "\n";
# Go send it
print "Sending...\n";
if (sendmail %mail) {
print "content of \$Mail::Sendmail::log:\n$Mail::Sendmail::log\n";
if ($Mail::Sendmail::error) {
print "content of \$Mail::Sendmail::error:\n$Mail::Sendmail::error\n";
}
print "ok - mail send to $mail{To}\n";
}
else {
print "\n!Error sending mail:\n$Mail::Sendmail::error\n";
print "not ok - mail not send\n";
}
print "<hr></pre>";
|