On Mon, 2008-08-18 at 17:50 +0800, loody wrote: > Dear all: > I use Mail::Sender to send mails. > But I have a problem. > How could I pass email address to the sendto parameter. > > Usually we use ' ' or "\@" to avoid taking care of @. > just like ex1 below. > > But I use an array to save my receivers and I want to pass them one by one. > like ext2 below. > And perl tells me I pass the wrong email address. > '$_' is wrong I know, since the parameter will not be interpreted. The > to will be $_. > "$_" is also wrong either, since @ in email address will cause the problem. > What can I do to have the same effect like "[EMAIL PROTECTED]" or '[EMAIL > PROTECTED]'. > appreciate your help, > miloody > > ex1: > if ($sender->MailMsg({ > smtp => 'mail.yourISP.com', > from => '[EMAIL PROTECTED]', > to =>'[EMAIL PROTECTED]', > subject => 'this is a test', > msg => "Hi Johnie.\nHow are you?" > }) < 0) { > die "$Mail::Sender::Error\n"; > } > print "Mail sent OK." > > ex2: > foreach (@receivers) > { > if ($sender->MailMsg({ > smtp => 'mail.yourISP.com', > from => '[EMAIL PROTECTED]', > to =>$_, > subject => 'this is a test', > msg => "Hi Johnie.\nHow are you?" > }) < 0) { > die "$Mail::Sender::Error\n"; > } > print "Mail sent OK." > } >
You escape a '@' inside a literal string so Perl won't interpret it as an array. This is only for strings appearing in the script itself. Strings obtain from elsewhere do not need this. If your script is saying you have an invalid email address, dump the addresses and check them. use Data::Dumper; print '@receivers : ', Dumper [EMAIL PROTECTED]; -- Just my 0.00000002 million dollars worth, Shawn "Where there's duct tape, there's hope." "Perl is the duct tape of the Internet." Hassan Schroeder, Sun's first webmaster -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/