SPUG: sendmail from Perl (quick newbie question)

dancerboy dancerboy at strangelight.com
Tue Feb 12 18:00:03 CST 2002

Okay, this is more of a sendmail question than a Perl question, but I 
figure there are many on this list who will be able to answer it in 
10 seconds flat, whereas it would take me considerable amounts of 
digging to find the answer in an "appropriate" forums...

How do you send to multiple addresses using sendmail?  I've got a 
super-simple form-to-email CGI that accesses sendmail like this:

     sub send_mail {
         my $mailprog = '/usr/lib/sendmail';
         my (
         ) = @_;

         ####  [ ... verifications omitted here for brevity ... ]

         open(MAIL,"|$mailprog -t") || die "Couldn't open |$mailprog -t: !";
             # Open The Mail Program

         (print MAIL "To: $to_addy\n")
             || die "Couldn't print to |$mailprog -t: $!";
         (print MAIL "From: $from_addy ($from_realname)\n")
             || die "Couldn't print to |$mailprog -t: $!";
         (print MAIL "Subject: $subject\n\n")
             || die "Couldn't print to |$mailprog -t: $!";
         (print MAIL "$msg_body\n")
             || die "Couldn't print to |$mailprog -t: $!";

         close (MAIL) || die "Error closing $mailprog: $!";

I now need to modify the form so that it sends copies of the message 
to multiple addresses.  I had thought that just putting multiple 
addresses on the "To:" line, separated by commas, would do the trick, 
but it doesn't:  when I set $to_addy to something like 
'test_address_1 at myserver.com, test_address_2 at myserver.com, 
test_address_3 at myserver.com' the message gets sent only to the first 
address in the list (test_address_1 at myserver.com) not to any of the 

What's the correct syntax for sending to more than one address?



 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     POST TO: spug-list at pm.org       PROBLEMS: owner-spug-list at pm.org
      Subscriptions; Email to majordomo at pm.org:  ACTION  LIST  EMAIL
  Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
 For daily traffic, use spug-list for LIST ;  for weekly, spug-list-digest
     Seattle Perl Users Group (SPUG) Home Page: http://seattleperl.org

More information about the spug-list mailing list