Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

multiple CC using sendmail

by Hammy (Scribe)
on Jun 25, 2007 at 23:52 UTC ( #623284=perlquestion: print w/replies, xml ) Need Help??
Hammy has asked for the wisdom of the Perl Monks concerning the following question:

Hello, I am using sendmail to push some dynamic emails to my users. I need to either CC or BCC multiple users. When I have one CC or one BCC it works well, but if I add an additional name separated by ';' I get a system error. If I separate by ',' it just does not work. The users are registering and I need to let many people know about the registration. The code I am using is below:
$lines[0] = "To: $email\n"; $lines[1] = "From: $from\n"; $lines[2] = "Bcc: support\\n"; $lines[3] = "MIME-Version: 1.0\n"; $lines[4] = "Content-Type: text/html; charset=us-ascii\n"; $lines[5] = "Subject: $subject\n\n"; $lines[6] = "$theMessage"; open(MAIL,"|/usr/sbin/sendmail -t") or fatal("..."); print MAIL @lines; close(MAIL) or fatal("...");
Is there something I am missing? Thanks for your help.

Replies are listed 'Best First'.
Re: multiple CC using sendmail
by Joost (Canon) on Jun 26, 2007 at 00:12 UTC
    First of all, IIRC, sendmail does not support separating adresses with ";", you need to use ",".

    Also "It just does not work" is not a good description of what's going wrong, so I can't really help you there. See also How do I post a question effectively?. Especially helpful would be: what does open(MAIL,"|/usr/sbin/sendmail -t") or fatal("..."); print to stderr?

    See also which describes how to send mail from perl using sendmail.

    Also also: there's no need to use the cumbersome array assignment to create the message. You can use "here docs" instead, for example:

    my $msg = <<"ENDMSG"; To: $email From: $from Bcc: support\ MIME-Version: 1.0 Content-Type: text/html; charset=us-ascii Subject: $subject $theMessage ENDMSG # continue here and print $msg to sendmail
      Thanks for your quick response. I appologize for not being specific about sending the emails. What I meant by does not work is:

      When separating by ',' - no emails are sent.

      Now I must clarify. I made your suggestion to use comma in the Bcc and it sent the email to everyone I asked it to. Great. So I went back to my original need which is multiple people in the To: field and it does not send an email to anyone in the To: field. So I had two people in the To: field and two people in the Bcc: field. Both Bcc: people arrived, neither To: field arrived.

      Thanks again.
Re: multiple CC using sendmail
by sago (Scribe) on Jun 26, 2007 at 09:29 UTC

    Try this code.

    use MIME::Lite;
    MIME::Lite->send('smtp', "", Timeout=>90);
    my $email = "This email was generated automatically.";
    my $subject = "hello test";
    my $MailFrom = "";
    my $to_list = ',,';
    my $cc_list = ',,';
    my $bcc_list = ',';
    $msg = MIME::Lite->new(
    From => $MailFrom,
    To => $to_list,
    Cc => $cc_list,
    Bcc => $bcc_list,
    Subject => $subject,
    Type => 'TEXT',
    Encoding=> '7bit',
    Data => $a
      Use the option -t to send it to multiple addresses in the "To" field.
Re: multiple CC using sendmail
by Anonymous Monk on Jun 26, 2007 at 05:03 UTC
    man sendmail

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://623284]
Approved by Joost
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2018-11-17 00:35 GMT
Find Nodes?
    Voting Booth?
    My code is most likely broken because:

    Results (200 votes). Check out past polls.

    • (Sep 10, 2018 at 22:53 UTC) Welcome new users!