package PL::Mail; use strict; use Mail::Sendmail; ## Only global is your server since it doesnt change (?) my $server = 'pop.dnvr.qwest.net'; ## The new constructor just sets up the server and the From address since these are static (could put the server name here directly and not have a global variable) sub new { my $class = shift; my $self = {}; $self->{mail}{Smtp} = $server; $self->{mail}{From} = 'Postmaster '; bless $self, $class; return $self; } ## The send method is passed a hashref, containing subject, message and optionally a to key. ## eg $obj->send({subject => 'testing', message => 'just trying to send mail', to => 'me'}); ## The $self hashref, which represents the object, is used to store all the parts of the %mail hash, which is then passed to sendmail sub send { my ($self, $data) = @_; $self->{mail}{To} = $data->{to} ? $self->{to} : 'Devin Austin '; $self->{mail}{Subject} = $data->{subject}; $self->{mail}{Message} = $data->{message}; my $date = Mail::Sendmail::time_to_date(); $self->{mail}{Message} .= <<"" Message sent on $date From $ENV{REMOTE_ADDR} All information contained in this message do not reflect the ideas of Devin Austin or MorningStarWeb and it's affiliates. ; if (sendmail %{$self->{mail}) { print STDERR $Mail::Sendmail::error; } else { print STDERR "Error sending mail ($date): $!"; } }