Page 2 of 2 FirstFirst 12
Results 11 to 15 of 15

Thread: How to throttle a simple emailer script to limit messages sent per hour

  1. #11
    Join Date
    Sep 2007
    Location
    Maui
    Posts
    642
    Thanks
    284
    Thanked 15 Times in 15 Posts

    Default

    The mail messages work! Yea! But the odd thing is that 158 lines were written to the text file but I received only 83 emails. There were quite a few duplicate email addresses so it is possible that it sent only one per address, but I didn't put anyhting in the code to filter out dups. Any idea why this would happen?

  2. #12
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Hmm... no. But first see my post (you might have missed it since we posted about the same time and your post made a new page). Let's see if we can fix that, then worry about the rest.
    It is possible that some simply were delayed sending so you may receive them soon. It's hard to know. There's also some remote possibility, I assume, that your server automatically ignores duplicate requests as a spam or overload precaution, but that is a complete guess and there's no reason to assume that's the case. You could try it manually I suppose and see what happens.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #13
    Join Date
    Sep 2007
    Location
    Maui
    Posts
    642
    Thanks
    284
    Thanked 15 Times in 15 Posts

    Default

    Yes, I did adjust the Email variable as follows...

    Code:
    while($row = mysql_fetch_assoc($result)){ 
      sql = "SELECT * FROM `booking` WHERE Book_First_Name = 'aa test' and laste <> '".$Today_ymd."' ";
      $result = mysql_query($sql,$connection) or die("Couldn't execute $sql query. <br> mysql error: ".mysql_error()); 
      //include('load-booking-variables.php');
      include('convert-dates-to-mdy.php');
      include('add-agency-logos.php'); 
    	
      $body = file_get_contents($Email_Alamo_Refund);
      include('replace-email-variables.php');
      
      // Send email to Client
      $Subject = "Notice Regarding Your Hawaii Car Rental";
      $emailaddress = $Email;
      echo $row['Email']; echo "<br>";

  4. #14
    Join Date
    Sep 2007
    Location
    Maui
    Posts
    642
    Thanks
    284
    Thanked 15 Times in 15 Posts

    Default

    OK, I ran the script for real and it added the send date to 159 records in the table (I added a test record), but it wrote only 83 lines to the text file. And there were 2 records with my email address, so I should have received 2 emails but received only one. Now I am worried that not all the people received the notice. I need to be able to trust the script or it isn't much use. Could you please tell me what is wrong, or could be improved in my code? I really need this script to work reliably as I'll need to use it over and over with different SELECT clauses. Thanks very much.

    Code:
    include('cr-connectdb.php');
    require('class.phpmailer.php');
    
    $Today_ymd = date("Y-m-d"); // 2010-08-31
    
    // Retrieve Records from booking table
    $sql = "SELECT `Book_Count` FROM `booking` WHERE `Book_Date` < '2010-6-30' AND `Book_Begin_Date` > '2010-8-31' AND (`Book_Comp` = 'Alamo' AND `country` NOT IN('CA', 'CW')) AND `Book_Pick` NOT LIKE 'Oahu%' AND `Book_Pick` NOT LIKE 'Maui - Kaan%' AND `Book_Confirm` <> 'Not Confirmed' ORDER BY `Book_Last_Name` ";
    $result1 = mysql_query($sql,$connection) or die("Couldn't execute $sql query. <br> mysql error: ".mysql_error()); 
    
    if(mysql_num_rows($result1) == 0){ echo "No rows returned\n"; exit; }	
    
    while($clientList = mysql_fetch_assoc($result1)){ 
      $sql = "SELECT * FROM `booking` WHERE Book_Count = '".$clientList['Book_Count']."'";
      $result = mysql_query($sql,$connection) or die("Couldn't execute $sql query. <br> mySQL Error: ".mysql_error()); 
      while($row = @mysql_fetch_array($result)){
        include('load-booking-variables.php'); 
        include('convert-dates-to-mdy.php');
        include('add-agency-logos.php');   
    		
        $body = file_get_contents($Email_Alamo_Refund);	
        include('replace-email-variables.php');
    		
        // Send email to Client
        $Subject = "Notice Regarding Your Hawaii Car Rental";
        $emailaddress = $Email;  
        echo $emailaddress; echo "<br>"; 
        include('send-client-email.php');   
    	
        // Report Entry
        $report = "Alamo Refund Info sent to: ".$name."  at  ".$Email."  on  ".$Today_mdy." \r\n";   
        $file = "/absolutepath/alamo-refund.txt";    
        if (!$file_handle = fopen($file,"a")) { echo "Cannot open $file file"; }   
        if (!fwrite($file_handle, $report)) { echo "Cannot write to $file file"; }    
        fclose($file_handle); 
    	
        // Set Last Email Date to current date
        $sql = "UPDATE booking SET `laste` = '".$Today_ymd."' WHERE `Book_Count` = '".$Book_Count."'" ;
        $result2 = mysql_query($sql,$connection) or die("Couldn't execute $sql query. <br> mysql error: ".mysql_error());
      }
    }
    Last edited by kuau; 09-01-2010 at 04:42 AM. Reason: formatting

  5. #15
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    The first place to start is that unless it works flawlessly, you should never use error suppression. Remove the @ and fix the related problems. Once you work that out everything may become clearer.

    From what I can tell something in your loop is wrong (not inside the loop, but in the loop operation itself), so you will need to make sure everything there is correct-- then it will loop the right number of times. Additionally, do you see any pattern about the 83 entries? There must be some reason they are separated. Alternatively, it might be overloading your server. This is unlikely but it's easy to test: just add a sleep(1) somewhere and see if it more consistently sends the emails (that is-- test by writing to a file, not live yet). Note that even 1 second will add up here, so disable any limits (usually 30 seconds) on your host or you'll have an unrelated problem.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

Bookmarks

Posting Permissions

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