View Full Version : My email scripts never ends and sends blank emails; Please assist!

01-25-2012, 11:54 PM
Hi all, I've just thrown this script together: quite basic but my knowledge in PHP is limited.

All I want it to do is send an email to all emails in a table.

I've told it to print out numbers instead of send emails; And it works fine (Stops at 140, the number of stored emails).
I've also told it to just send an email to me and ignore the while loop when the script is run: it works fine, with the correct body, header, subject etc.

BUT when I tell it to actually start mailing, it'll send everyone "No Subject" and blank messages AND will not auto-stop (Keeps going and going). Can anyone help rectify this: Been bugging me for hours!

*Apologies, I see how the "Blank email" thing happens: Some un-needed variable declarations! Corrected that, but the infinite sending still persists.

include 'db.php';

$emailsubject = "Test Subject Here";
$emailbody = "Test Body Here
More Testing

Format Test. ";

ini_set('max_execution_time', 300); //300 seconds = 5 minutes

$query = "SELECT email FROM tableNameHere";
$result = mysql_query($query);
$fromaddress = "myEmailHere";
$count = 1;

while ($row = mysql_fetch_assoc($result))

mail($row['email'], $emailsubject, $emailbody, "From: " .$fromaddress. "\nX-Mailer: PHP 4.x");

echo $row['email'] . "has been sent the email! ($count)<br /> ";


01-26-2012, 04:31 AM
You can add a limit to the query table to stop it.

You aren't telling the while loop where to stop, which might affect it. Such as while ($count < 140)