Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
01-25-2012, 10:54 PM #1
- Join Date
- Jan 2012
- Thanked 0 Times in 0 Posts
My email scripts never ends and sends blank emails; Please assist!
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.
$emailsubject = "Test Subject Here";
$emailbody = "Test Body Here
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 /> ";
Last edited by ogran; 01-25-2012 at 11:22 PM. Reason: Saw error
01-26-2012, 03:31 AM #2
- Join Date
- Apr 2010
- Thanked 108 Times in 107 Posts
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)
Been a sign maker for 8 years. My business:
American Made Signs