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.

function mail_list($ml_array,$subject,$message,$from) {
  foreach($ml_array as $name => $email) {
    $message = str_replace("((name))",$name,$message);
    if(@mail($email,$subject,$message,"Content-type: Text/HTML;From:".$from.";Reply-To:".$from.";")) {
    else {
      $errors[] = "Failed to send email to ".$email.".";
  if($i==sizeof($ml_array)) return true;
  else return implode("<br/>",$errors);
11 Years
Discussion Span
Last Post by sonny.scroggin

This is great! I've been thinking about how to create a script that would do just this!

I'm still learning php so I have a question regarding how to initiate the array to pull the a list of email addresses from a mysql database.

Could you help me with that?

Thank you,


Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.