Loop email reading flat file


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  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 = file("email-list.txt"); // load from a flat file, assuming 1 email per line in the file
  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 arrar
  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. ?>

URL: http://phelps.impactwow.com

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.