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

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.