Posted By

benphelps on 08/10/08


Tagged

email array loop mass


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

benphelps
vali29


Loop email reading an Array


 / Published in: PHP
 

URL: http://phelps.impactwow.com

  1. <?php
  2.  
  3. set_time_limit(0); // this will keep the script from stopping if it takes longer then 30 seconds, must have this here
  4. $emailaddress = array('[email protected]', '[email protected]', '[email protected]', '[email protected]', '[email protected]', '[email protected]');
  5. $emailsubject = "This is a sample subject!";
  6. $emailbody = file_get_contents("email.html");
  7. $fromaddress = "[email protected]";
  8. $i = count($emailaddress);
  9. $z = 0;
  10.  
  11. // here we check how many email address's we have, if its is 0, then we don't start the email function
  12. if ($i != 0)
  13. {// start if
  14.  
  15. // Lets loop until we reach the count from email address array
  16. while ($i != $z)
  17. {// start while
  18.  
  19. // here we send the email to the varables from above, using the email array incrament
  20. mail($emailaddress[$z], $emailsubject, $emailbody, "From: " .$fromaddress. "\nX-Mailer: PHP 4.x");
  21.  
  22. // lets echo out that the email was sent
  23. echo $z + 1 . " out of " . $i . " emails sent. (" . $emailaddress[$z] . ")<br>";
  24.  
  25. // increment the array one, so we get a new email address from the array
  26. ++$z;
  27.  
  28. }// end while
  29.  
  30. }//end if
  31.  
  32. else
  33. {//start else
  34.  
  35. // we echo out that no emails where found in the array and end the script
  36. echo "Warning: No emails in array.";
  37.  
  38. }// end else
  39.  
  40. ?>

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: SeanJA on August 15, 2008

I have had scripts run for 256 seconds... granted I was inserting over 500 000 records into a database, but I haven't seen my scripts time out before...

You need to login to post a comment.