Running this gives me this in the logfile:#!/usr/bin/perl -w use strict; use warnings; use diagnostics; use Mail::Mailer; my $ourEmail = 'our email'; my $theirEmail = 'their email'; my $mailServer = 'our smtp'; my $logFile="logfile"; my $orderSubject = "Order Information"; my $reportSubject = "Order Report"; # begin main program &log("\n=============================================="); &log("\nBegining program"); # send out emails &mailOrder; &mailReport; print "content-type: text/plain\n\n"; &log("Completed program (OK)"); &log("=============================================="); # end main program sub exit_app { my $why=shift; &log("$why"); exit(1); } sub log { my $logText=shift; open LOG, ">>$logFile"; print LOG "$logText\n"; close LOG; } sub mailOrder { my $orderBody = "Welcome"; eval { my $orderMailer = new Mail::Mailer 'smtp', Server => $mailServer; $orderMailer->open ( { From => $ourEmail, To => $theirEmail, Subject => $orderSubject, } ); print $orderMailer $orderBody; $orderMailer->close(); }; if ($@) { # sending mail failed &exit_app("Could not send order e-mail! (FAILED): $@\n"); } else { # mail was sent &log("The order was e-mailed successfully (OK)"); } } sub mailReport { my $reportBody = "This is the order report"; eval { my $reportMailer = new Mail::Mailer 'smtp', Server => $mailServer; $reportMailer->open ( { From => $ourEmail, To => $ourEmail, Subject => $reportSubject, } ); print $reportMailer $reportBody; $reportMailer->close(); }; if ($@) { # sending mail failed &exit_app("Could not send report e-mail! (FAILED): $@\n"); } else { # mail was sent &log("The report was e-mailed successfully (OK)"); } }
Running this gives me this at the console:============================================== Begining program The order was e-mailed successfully (OK) The report was e-mailed successfully (OK) Completed program (OK) ============================================== The order was e-mailed successfully (OK) The report was e-mailed successfully (OK) Completed program (OK) ============================================== The report was e-mailed successfully (OK) Completed program (OK) ============================================== The report was e-mailed successfully (OK) Completed program (OK) ==============================================
content-type: text/plain content-type: text/plain content-type: text/plain content-type: text/plain
In reply to Re^4: Mail::Mailer in a sub question.
by docster
in thread Mail::Mailer in a sub question.
by docster
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |