Sending email to multiple recipients

谁都会走 提交于 2019-12-05 09:58:33

Do it like this:

use Net::SMTP::Multipart;
$to1 = "sam\@bogus.com"; 
$to2 = 'tom@foo.com';
$smtp = Net::SMTP::Multipart->new($smtpserver);
$smtp->Header(To    =>  [ $to1, $to2, 'another_email@server.com' ],
              From  =>  "junk\@junk.com",
              Subj  =>  "This is a test.");
$smtp->Text("Hello, world!\n");
$smtp->End();

Notice that if you use double-quotes, you should escape the @ in the email addresses, or perl may try to interpret it as an array interpolation.

Instead of separating the email addresses with spaces, use a comma with no intervening spaces. This works for me..

user3616273

Declare an array and put all the email id's like

@MailTo = ('mail1@demomail.com', 'mail2@demomail.com', ...., 'mailn@demomail.com')

Now use the Net::SMTP module to send out the emails

$smtp->to(@MailTo);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!