multiple cc & bcc in mail()

the mail() function

Moderators: macek, egami, gesf

azw
New php-forum User
New php-forum User
Posts: 41
Joined: Fri Oct 11, 2002 9:13 pm
Contact:

multiple cc & bcc in mail()

Postby azw » Fri Feb 06, 2004 3:23 am

Hi,
I need to send an email to 4 people. Do I have to call mail() 4 times, or can I set up a cc: with 3 addresses?

I've not had success in getting the emails to go to all 4 addresses. Here's one version I tried:

Code: Select all

  $ccEmail1 = "\"" . $name1 . "\" <" . $email1 . ">";
  $ccEmail2 = "\"" . $name2 . "\" <" . $name2 . ">";
  $ccEmail3 = "\"" . $name3 . "\" <" . $email3 . ">";

...
  $rHeaders .= "Cc:  " . $toEmail1 . ", " . $toEmail2 . ", " . $toEmail3 . "\n";
...


Am I on the right track?

Also, if I use mail() to send an email to 4 different addresses at the same time, all to the same domain (they're all me), I should get 4 emails, shouldn't I? I'm not getting them, and I just wanted to be sure that it wasn't a "feature" of the mail server or Apache or something to delete duplicates to the same address when sent with the same call to mail().

sigix
php-forum Active User
php-forum Active User
Posts: 364
Joined: Mon Jul 14, 2003 9:39 pm
Location: /Earth/Xion

Postby sigix » Fri Feb 06, 2004 6:34 am

you can use comma separated list.

Code: Select all

<?php
mail("one@php.com,three@php.com,five@php.com,seven@php.com","Subject","Msg","Headers: true");
?>

azw
New php-forum User
New php-forum User
Posts: 41
Joined: Fri Oct 11, 2002 9:13 pm
Contact:

Postby azw » Fri Feb 06, 2004 11:24 am

Hmm. Strange.

I think I've got that. I'll test it again.

Is there any chance that some part of the system deletes duplicates emails to the same address when sent with the same call to mail()?

User avatar
swirlee
Moderator
Moderator
Posts: 2272
Joined: Sat Jul 05, 2003 1:18 pm
Location: A bunk in the back
Contact:

Re: multiple cc & bcc in mail()

Postby swirlee » Fri Feb 06, 2004 4:16 pm

You may have to put each CC'd address on its own line, like so:

Code: Select all

<?php
$mail_to = '"swirlee" <swirlee@php-forum.com>';
$mail_from = '"azw" <azw@php-forum.com>';
$mail_subject = 'This isn\'t spam, I swear!'
$mail_body = <<<EOT
Some body text goes here.
EOT;
$cc1 = '"Somebody Jones" <somebody@jones.com>';
$cc2 = '"Somebody Else-Jones" <somebody@else.com>';
$bcc1 = '"Mr. C.C. Blind" <bcc@ccb.net>';

if(mail(
   $mail_to,
   $mail_subject,
   $mail_body,
   /* extra headers: */
   'From: ' . $mail_from . "\n" .
   'cc: ' . $cc1 . "\n" .
   'cc: ' . $cc2 . "\n" .
   'bcc: ' . $bcc1 . "\n" .
   "\n" // for good measure
)) {
   echo 'Mail sent.';
} else {
   echo 'Error sending mail.'
}

azw
New php-forum User
New php-forum User
Posts: 41
Joined: Fri Oct 11, 2002 9:13 pm
Contact:

Postby azw » Sat Feb 07, 2004 12:00 am

Error in conclusions. Deleted message.
Last edited by azw on Sat Feb 07, 2004 1:36 am, edited 1 time in total.

User avatar
swirlee
Moderator
Moderator
Posts: 2272
Joined: Sat Jul 05, 2003 1:18 pm
Location: A bunk in the back
Contact:

Postby swirlee » Sat Feb 07, 2004 12:58 am

azw, if you're operating some sort of mailing list, you shouldn't be using CCs or BCCs -- you should be a separate e-mail to each recipient. Using CCs and BCCs reveals the e-mail address of some recipients to other recipients, which is a breach of privacy. I recommend that you use some commercially or freely available mailing list software.

azw
New php-forum User
New php-forum User
Posts: 41
Joined: Fri Oct 11, 2002 9:13 pm
Contact:

Postby azw » Sat Feb 07, 2004 1:01 am

Actually, all I'm doing is sending a copy of customer inquiries to several different people in the same organization. So in this case a cc: would do, except that it won't work! P-r-e-t-t-y frustrating!


Return to “PHP coding => Mail”

Who is online

Users browsing this forum: No registered users and 0 guests