User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 330,320 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,736 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Sep 21st, 2007
Views: 1,973
This function distributes mail to a mailing list, out of an array. Wether the array is plundered from a database, a file, or from the code, the function only takes a prepared one. Also, this function is only good for HTML messages.

The array's syntax is to be:
array("recipent's name"=>"email","recipent's name"=>"email","recipent's name"=>"email");

In-order to insert the name into the email, just use ((name)), as it will be replaced with the array-given value.
$from is for the email you want to be replied to.
If all recipents were mailed successfully, the function returns true, else it returns the errors.
You can use it like so:
if($handle=@mail_list($array,$subject,$message,$from)) {
  #...#
}
else {
  echo $handle;
}
If you want, I can make another function with a lot more variables to send. Just request it via comment, please.
Last edited : Sep 21st, 2007.
php Syntax | 5 stars
  1. function mail_list($ml_array,$subject,$message,$from) {
  2. $i=0;
  3. foreach($ml_array as $name => $email) {
  4. $message = str_replace("((name))",$name,$message);
  5. if(@mail($email,$subject,$message,"Content-type: Text/HTML;From:".$from.";Reply-To:".$from.";")) {
  6. $i++;
  7. }
  8. else {
  9. $errors[] = "Failed to send email to ".$email.".";
  10. }
  11. }
  12. if($i==sizeof($ml_array)) return true;
  13. else return implode("<br/>",$errors);
  14. }
Post Comment

Only community members can submit or comment on code snippets. You must register or log in to contribute.

DaniWeb Marketplace (Sponsored Links)
All times are GMT -4. The time now is 7:57 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC