Ok here is a complete program that for me sends 1 extra email and prints 3 "extra" loops. Sorry for the simple questions and thanks for the help! I am trying here ;)
#!/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 in the logfile:
============================================== 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) ==============================================
Running this gives me this at the console:
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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.