sub mailThis { $mailServer = "serverName"; $ourEmail = 'ourEmail'; $theirEmail = 'theirEmail'; $subject = "Test Email"; $body = "Welcome $username"; eval { $mailer = new Mail::Mailer 'smtp', Server => $mailServer; $mailer->open ( { From => $ourEmail, To => $theirEmail, Subject => $subject, } ); print $mailer $body; $mailer->close(); }; if ($@) { # sending mail failed } else { # mail was sent } }