Simple Mailer

Here's a function that can be used for a quick-and-dirty e-mail. It doesn't do anything particularly amazing, just sends a text message.


Place the following configuration variables at the top of the script and change them as desired.

# location of mail program 
  $mailer = "/bin/sendmail";
# mail recipient
  $mailto = 'recipient@email.com';

# code passed on subject line for e-mail filtering
  $fcode = "4229";

The third is optional, but I find it useful in filtering and sorting inbound mail to make sure messages from the Web don't get lost in the spam.

QuickMail Function

Here's the utility function for sending the mail. It can be included anywhere in the context of the script.

sub quickMail{
  open(MAIL,"|$mailer -t") || &scriptError(999);
  print MAIL "To: $mailto \n"; 
  print MAIL "From: $qm{'sender'} \n";
  print MAIL "Subject: $fcode - $qm{'subject'}\n\n";
  print MAIL "$qm{'content'}\n\n";
  print MAIL "$qm{'footer'}\n\n";
  close (MAIL);

If you opt not to use a subject line code, strip that out. And change the error code to something more useful (see my "script template" if you don't know what that refers to).


To run the function, populate the following variables:

Then call the function - &quickMail - and the deed is done.


It should be fairly simple to hack it up to a variety of uses, including HTML formatting the message (if you're into that) or sending a message with an attachment, but that's beyond the scope of a "simple" mail function. This is just the basics, quick and dirty.

And finally

This is online for my own use and reference, but feel to snag it if you think it would be useful. It's a trifle and I don't expect to be credited or compensated in any way ... but nor does it come with any sort of guarantee.