Hi, I am writing a CGI script to send email to one or more recipients. I have tried using both Mail::Mailer and MIME::Lite, with varying degrees of failure. I got Mail::Mailer to send email out using the following code:
$address='one@example.com, two@example.com'; use Mail::Mailer; $msg = Mail::Mailer-> new('smtp', Server=>'mysmtp.server.com'); $msg->open({ From => 'sender@example.com', To => "$address", Subject => 'Subject', }); print $msg 'Body text here'; $msg->close();
No email ever arrives however, not even a bounce. I looked at the Exim logs on mysmtp.server.com, and it gives the following error:
2003-09-19 10:28:30 SMTP call from (clientname)(localhost.localdomain) + [IP address] dropped: too many unrecognized commands
It's probably a daft error somewhere, but I'm very new to Perl and can't see the problem from the documentation I've read. I tried two approaches with MIME::Lite. The first works perfectly if I sepecify the "To" line as follows:
To => 'one@example.com, two@example.com',
but if I use:
$address='one@example.com, two@example.com'; my $msg = MIME::Lite-> new( From => 'sender@example.com', To => "$address", Cc => 'three@example.com', Subject => 'Subject', Type => 'text/plain', Data => 'Body text here' ); $msg-> send('smtp', "mysmtp.server.com", Timeout=>60);
It will only send to the first address in the list. This also happens if I swap the entries for "To" & "Cc" round. The second approach was to to use a loop to send the mail as follows:
use Mime::Lite; use Text::ParseWords; # $address is actually taken from a combo box on a web page # but equals the definition below. # That's why I have done the array like this. $address='one@example.com, two@example.com, three@example.com'; @addresses = parse_csv($address); while(@addresses) { my $msg = MIME::Lite-> new( From => 'sender@example.com', To => shift(@addresses), Subject => 'Subject', Type => 'text/plain', Data => 'Body text here.' ); $msg-> send('smtp', "mysmtp.server.com", Timeout=>60); } .... sub parse_csv { return quotewords("," => 0, $_[0]); }
This only sends mail to the first recipient as well. It goes through the loop the requisite number of times. I put a "print" statement in there to make sure. I'm sorry this is such a long question. Hopefully there is an easy solution. I've only used Perl for a week, so I've probably missed something obvious. All help very gratefully received! Thanks, Andy.

In reply to Mail::Mailer & MIME:Lite On Win2k by Murf

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.