I have this script from a PHP for Flash book.
I am trying to use it to send out a newsletter to a mailing list I have. It is sort of working but I know that all the emails don't get sent. If I have only a few addresses in there it works perfect. If I put like 600, it freaks out! It seems to stop somewhere in the middle of the list and loop back to the top so 2 emails get sent to the addresses. I think the script is trying to send out all the emails at once. I would like to set a delay between each sent email so the server doesn't get hit so hard.
Any ideas?
<?
function sendEmail ($mailSubject, $mailBody) {
// Register global variables
global $subsFile;
// Set up reply address for mailing list
$mailFrom = "Kylie Ireland Newsletter <mailinglist@kylieireland.com";
// Ensure that subject and body of email have
// automatically inserted escape slashes removed
$mailSubject = stripslashes($mailSubject);
$mailBody = stripslashes($mailBody);
// Attempt to read subscriber file
$subscribers = file($subsFile);
// If file open failed...
if (!$subscribers) {
// Output error information and quit
print "Couldn't open subscriber file or no subscribers listed";
exit;
}
// For each subscriber line...
foreach($subscribers as $subscriber) {
// split subscriber info into array
$info = explode('|', $subscriber);
// Assign array to meaningful variable name
$name = $info[0];
$email = $info[1];
$joined = $info[2];
// Build to address including subscriber name
$mailTo = "$name <$email>";
// Send email to
mail($mailTo, $mailSubject, $mailBody, "From: " . $mailFrom);
}
print "Email sent to all subscribers";
}
?>