I'm about to pull my hair out over here. I wanna blame yahoo, really I do. Here's what's going on.
We have a mailing list that we occasionally send out promotional specials to. There are over 500 people signed up. Yahoo limits mail created by scripts to 250 a day. So I created a php page that grabs all of the signed-up emails out of the database. I put 250 of them on a page. Each one has a checkbox (default to on) that determines whether or not they get the newsletter. So, in reality, all you have to do is type the letter and press send. For every email with a checkmark, the address gets put in an array. The array is passed to the page that sends the mail, which uses a for loop to go thru the array and send the mail. It also updates the database with a count of how many emails were sent, and who it was sent to.
But we've been having problems. Sometimes the emails go out. Sometimes they don't. Sometimes they go to some people and not others. I figure if it was my code, it would either work or not work, not be so unpredictable.
Also, at the end of sending the email, it's supposed to pop up a page that says "Newsletter sent" and to whom. Sometimes this page times out, but every email addy that it was supposedly sent to is in the db, and the count of sent emails is what it is supposed to be. So somewhere the mail is going into never never land.
I'd really appreciate any help at all. It's just bugging the poop outta me.
The email addy listed as the FROM address is actually an alias that points to info@...
Here's the code for the script that sends the email. Is there really anything that would stop the mail from going out? Thanks in advance for any insight.
<?
$strOutput = "";
require("dbutil.php");
$sql = new MySQL_class;
$sql->Create("Members");
$today = date("Y-m-d");
$sqlquery = "SELECT eCount, sentTo FROM Emails, EmailSentTo WHERE (Emails.dateSent = EmailSentTo.dateSent) and (Emails.dateSent = '" . $today ."')";
$sql->Query($sqlquery);
for ($i = 0; $i < $sql->rows; $i++) {
$sql->Fetch($i);
$sentToday = $sql->data["eCount"];
$sentTo = $sql->data["sentTo"];
} //for loop
if (is_null($sentTo)) {
$sentTo = "";
}
$eLog="../../tmp/mailError.log";
//Get the size of the error log
//ensure it exists, create it if it doesn't
$fh = fopen($eLog, "r");
fclose($fh);
$originalsize = filesize($eLog);
$comments = $_POST["Comments"];
$headers = "From:The Bulldog<bulldog@draftfreak.com>\nReply-To:bulldog@draftfreak.com";
/********MAIL TO THE BULLDOG********/
mail("bulldog@draftfreak.com", "Bulldog Newsletter",$comments,$headers);
/********MAIL TO THE MEMBERS********/
foreach($_POST['emailuser'] as $email) {
mail($email,"Bulldog Newsletter",$comments,$headers);
$sentToday += 1;
$strOutput = $strOutput . " <br> " . $email;
if ($sentToday <= 250) {
$sentTo .= ", " . $email;
}
}
/*
* NOTE: PHP caches file status so we need to clear
* that cache so we can get the current file size
*/
clearstatcache();
$finalsize = filesize($eLog);
//Check if the error log was just updated
if ($originalsize != $finalsize) {
print "<p><font color=red><b>There was a problem sending the mail. Please try again later.</b></font></p>";
} else {
$sqlquery = "UPDATE Emails SET eCount = " . $sentToday . " WHERE dateSent = '" . $today . "'";
$sql->Update($sqlquery);
$sqlquery = "UPDATE EmailSentTo SET sentTo = '" . $sentTo . "' WHERE dateSent = '" . $today . "'";
$sql->Insert($sqlquery);
echo "<p class=bodymd align=center><font color=white><b>Newsletter sent.<br>To: $strOutput</b></font></p>";
exit();
}
?>