I have written a program that does a newsletter for our business. I am using MIME::Lite as the module for doing the sending. Here is the subroutine that I am passing data to from a Database.
sub sendEmail { my($email, $c_first) = @_; $msg = MIME::Lite->new( To =>$email, From =>'marketing@taieriprint.co.nz', Subject =>$subject, Type =>'multipart/related' ); $msg->attach(Type => 'text/html', Data => qq{<html> <HEAD> <TITLE>Taieri Print Ltd</TITLE> </HEAD> <body bgcolor="#DBDBDB"> <table align="center" width="645" border="0" bgcolor="whit +e"> <tr><td align="center"><img src="cid:tplogo.gif"></td> </tr><tr height="3" CELLPADDING=20><td align="right"><font siz +e="2" face="Microsoft Sans Serif">$Month $Year</font></td></tr></tabl +e> <table CELLPADDING=20 align="center" width="645" bgcolor="whit +e"> <tr><td align="left"><font face="Microsoft Sans Serif" size="2 +">Dear $c_first,</font><br> <font face="Microsoft Sans Serif" size="2">$message</td></tr>< +/font> <tr><td align="center"><font size="1" face="Microsoft Sans Ser +if"><br>We hope you have enjoyed recieving this message. However, if you'd rather not recieve future newsletters from u +s, then please <a href="mailto:mailbird&#64;taieriprint.co.nz?subject=Unsubsc +ribe"> click here</a> to unsubscribe. </td></tr></table> </body> </html> } ); $msg->attach(Type => 'image/gif', Id => 'tplogo.gif', Path => 'C:/mailbird/tplogo_new.gif', ); if ($query->param('attach')) { $msg->attach(Type => 'application/pdf', Path => $attachment, Filename => $filename); } $msg->send('smtp', 'smtp.taieriprint.co.nz') or warn print "Una +ble to send email: $_"; return; }
I am wanting to write to a file any emails that are unable to be sent, rather than the application 'dying'. This will ensure that a bogus email address doesn't stop the rest of the emails being sent. For the $msg->sent part of the subroutine I have tried using or warn and printing to a file with no success. Can someone please give me a idea on how to achieve this goal. Thankyou very much.

In reply to Email error checking by Anonymous Monk

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.