| Home > Computer & I'net > Email - Multiple Recipients... |
|
|
|||||||||||||||
|
|
|||||||||||||||
|
||||||||||||||||
Email - Multiple Recipients | |
$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. | |
| Articles |
•Auto & Trucks•Business•Computer & I'net·General·Apache·CSS·Database·Hardware·HTML·Javascript&DHTML·Linux·MySQL·Operating System·Perl / CGIPHP·Programming·Publishing·Search Engines·Software Problems·SSI·Tips & Tricks·Utilities·Web Design•Family•Food & Drink•Gardening•Health•Other•Pets•Psychology•Spiritual•Travel•Women |
| Calculators |
|