Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-25-2012, 10:54 PM   PM User | #1
ogran
New to the CF scene

 
Join Date: Jan 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
ogran is an unknown quantity at this point
Angry 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.

PHP Code:

<?php
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 /> ";
 
$count++;


}

Last edited by ogran; 01-25-2012 at 11:22 PM.. Reason: Saw error
ogran is offline   Reply With Quote
Old 01-26-2012, 03:31 AM   PM User | #2
myfayt
Senior Coder

 
Join Date: Apr 2010
Posts: 1,156
Thanks: 46
Thanked 95 Times in 94 Posts
myfayt can only hope to improve
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 5 years. My business:
American Made Signs
myfayt is offline   Reply With Quote
Reply

Bookmarks

Tags
mailing, mysql, php, script, spam

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:39 AM.


Advertisement
Log in to turn off these ads.