Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks, I'm having a set users in a array whom i need to send a mail using MI +ME::Lite, I'm using the below code but facing an error as can't extra +ct address. Am I doing anything wrong. my @arr = qw( 'abc' 'efg' 'xyz'); my $users = undef; foreach (@arr){ $users.= '$_.@gmail.com', } #print $users my $subject ="hai team this is a test mail"; my $msg=MIME::Lite->new( From =>'admin@xyz.com', To => $users, Subject =>'Test mail Pl ignore!!!', Type =>'multipart/mixed'); $msg->attach(Type =>'TEXT', Data => $subject); MIME::Lite->send('smtp', $mail_host, Timeout=>60); $msg->send; print " Hai";

Replies are listed 'Best First'.
Re: Sending mail to multiple users using MIME
by hipowls (Curate) on Jan 25, 2008 at 08:39 UTC

    The lines

    foreach (@arr){ $users.= '$_.@gmail.com', }
    are incorrect, the string is in single quotes and so $_ is not interpolated. They should be replaced with
    $users = join ', ', @arr;

      More than that, you should send the email 'To' one address, and CC (or BCC) to one or multiple email addresses.

      Replacing ' with "" you will send emails to 'foo@gmail.combar@gmail.comkaboom@gmail.com' which I guess you can figure out is wrong :)

      What you should do is to send the email 'To: one@email.address.here' and 'CC: to@one.address.here, the.second@one.here' and so on ...

      Just have a look at MIME::Lite examples

      Dodge This!
Re: Sending mail to multiple users using MIME
by Corion (Patriarch) on Jan 25, 2008 at 07:13 UTC

    Have you printed out your recipient email adresses? Are you sure that they are what you think they should be?

    print "Sending mail to $users. Hai guise!\n";

    You might want to read up on how double quotes (") are different from single quotes ('), in perlop.