About us Privacy Disclaimer Contact us
FAQ Help Advertising Feedback
Home Sitemap Search Donate us

  Home > Computer & I'net > Email - Multiple Recipients...

   Browse by title articles:
   What is hot:

Date

File Permissions

File Open and Close

Creating Directories

Email - Basics

Email - Multiple Recipients

Usability and Cost Savings while Designing an Intranet
Web Designing Tips
How To Format Your Hard Drive Properly
How to succeed with the Search Engines
Prev articles12345678910 11 12Next articles



Email - Multiple Recipients


Computer & I'net articlesEmail - Multiple Recipients

by David Stanley    



Additional recipient emails can be added to the first variable separating them by commas, not semicolons.

$to = "yourplace@somewhere.com,another@elsewhere.com";

A more advanced method is to put a newline separated email list into a text file, trim each entry, implode them into an array variable, and use the array variable as the $to value.

elist.txt
firstemail@here.com
secondemail@there.com
yourplace@somewhere.com
another@elsewhere.com

Revised email script
<?php
// read the list of emails from the file.
$email_list = file("elist.txt");

// count how many emails there are.
$total_emails = count($email_list);

// go through the list and trim off the newline character.
for ($counter=0; $counter<$total_emails; $counter++) {
   $email_list[$counter] = trim($email_list[$counter]);
   }

// implode the list into a single variable, put commas in, apply as $to value.
$to = implode(",",$email_list);

$subject = "My email test.";
$message = "Hello, how are you?";

if ( mail($to,$subject,$message) ) {
   echo "The email has been sent!";
   } else {
   echo "The email has failed!";
   }
?>

Having a newline separated list is much easier to manage and edit. An alternative would be to start off with a long comma separated list and get rid of the TRIM and IMPLODE command lines.




-----------------
Article by David Stanley. Visit his site http://www.htmlite.com. Reprinted with permission.





Amortization




  Disclaimer | Privacy | Terms of useCopyright © 2004 Nice2know.com