View Full Version : Using PHP for e-mail

2005-11-29, 04:31

I want to know how to send mails to multiple email addresses using PHP code.


2005-11-29, 07:34
// multiple recipients
$to = 'aidan@example.com' . ', '; // note the comma
$to .= 'wez@example.com';[/b]

//other stuff for messages and headers

// Mail it
mail($to, $subject, $message, $headers);
Nice and easy, just add a comma between the recipients...and I guess a space, but I kinda doubt that is necessary.

I grabbed this from php.net's (http://us2.php.net/manual/en/function.mail.php) explanation of the mail() function.

2005-11-29, 10:36
This will reveal everyone's addresses to everyone else tho'. If you are looking for a method to send it to everyone on a mailing list then there are two options.
1.) Loop through the addresses and send a copy to each person.

$to_list = array('rod','jane','freddy');
foreach($to_list as $to){
mail($to, "Subject","Message","Headders");

2.) Address the email to yourself, and then add everyone else as a BCC recipient. (You have to google for this one, I cannot remember the code off the top of my head.)

2005-11-29, 10:41
Thread split.

2005-11-29, 10:48
I am not positive, and again, you can look around, but I think you can just add Bcc to the headers and list multiple emails with a comma like you would the $to string.

// Additional headers
$headers .= 'To: Mary <mary@example.com>, Kelly <kelly@example.com>' . "\r\n";
$headers .= 'From: Birthday Reminder <birthday@example.com>' . "\r\n";
$headers .= 'Cc: birthdayarchive@example.com' . "\r\n";
$headers .= 'Bcc: birthdaycheck@example.com' . "\r\n";

// Mail it
mail($to, $subject, $message, $headers);

So you can see how you would add the headers...however if I was going to send to multiple I'd do the following...

$headers .="Bcc: birthdaycheck@example.com, birthdayarchive@example.com';

Again I think, I can't be positive unless I try it...and I can't right now. But YOU could :D Let me know.