Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Jan 2012
    Thanked 0 Times in 0 Posts

    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:

    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");
    $row['email'] . "has been sent the email! ($count)<br /> ";

    Last edited by ogran; 01-26-2012 at 12:22 AM. Reason: Saw error

  2. #2
    Senior Coder
    Join Date
    Apr 2010
    Thanked 110 Times in 109 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


Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts