Hi,

Here is the full on script that I have been using.

<CODE>------------------------------

<?php
require_once ('start_session.inc');
require_once ('../templates/login.php');
require ('../lib/phpmailer/class.phpmailer.php');

$css = 'css/admin.css';

$track_id = $_GET['track_id'];
$ic_id = $_GET['ic_id'];
$start = $_GET['start'];
$email_errors = 0;
$count = $_GET['count'];
$error_flag = 0;

require ('../templates/elist_include.inc');
list ($ic_html, $ic_text, $subject) = build_code($ic_id); // Build  
the code for the listings. (this is in the file above)

$header =  
"======================================================================= 
=======\n";
$header .= "Business Name\n";
$header .=  
"======================================================================= 
=======\n\n";
$ic_text = $header.$ic_text;

// Send the email

$mail = new PHPMailer();

$mail->From     = "[EMAIL PROTECTED]";
$mail->FromName = "CruiseExperts - InnerCircle";

$email_address_query  = "SELECT email_id, email, email_unique_id FROM  
inner_circle_email WHERE email_id > ".$start." ORDER BY email_id";
$email_address_result = mysql_query($email_address_query);

while ($email_address_row = mysql_fetch_array($email_address_result,  
MYSQL_ASSOC)) {
$ic_html_final = str_replace("<<EMAIL_ID>>", $email_address_row 
['email_unique_id'], $ic_html);
$ic_text_final = str_replace("<<EMAIL_ID>>", $email_address_row 
['email_unique_id'], $ic_text);
$mail->Subject = $subject;
$mail->Body    = $ic_html_final;
$mail->AltBody = $ic_text_final;
$mail->AddAddress($email_address_row["email"]);

if(!$mail->Send()) {
   $error_flag = 1;

   $error_report_query = "INSERT INTO ic_error_report VALUES ('". 
$track_id."','".$email_address_row['email_id']."','".$mail- 
 >ErrorInfo."',0)";
   $error_report_result = mysql_query($error_report_query);

   $email_errors++; // Add 1 to $email_errors so that it comes up  
with the correct number of emails NOT sent. Display that info after  
going through all the emails.
}
// Clear all addresses for next loop.
$mail->ClearAddresses();
// Write the email_id and incremented number back to the tracking table.
$count++;
$track_query = "UPDATE ic_track SET current_email_id = '". 
$email_address_row['email_id']."', count = '".$count."', email_errors  
= '".$email_errors."' WHERE track_id = ".$track_id;
$track_result = mysql_query($track_query);
}

if ($error_flag == 0) {
$track_status_query = "UPDATE ic_track SET status = 'finished' WHERE  
track_id = ".$track_id;
$track_status_result = mysql_query($track_status_query);
} else {
$track_status_query = "UPDATE ic_track SET status = 'error' WHERE  
track_id = ".$track_id;
$track_status_result = mysql_query($track_status_query);
}

echo "Email sent.";
exit;

?>

<?CODE>----------------------------------

This has worked great, but has as the list has grown, I've been  
getting duplicate emails sent. So that is the reason for  
troubleshooting this. It looks like the script was running twice  
because I couldn't see anywhere how each email was being sent out  
twice while the script ran once. I was leaving the script call window  
(frame) open, and was wondering if the the browser was timing out or  
something... I don't know. I'm at a frustrated loss.

Mark

--------------------------

On Nov 23, 2006, at 5:54 AM, Mike Brandonisio wrote:

> Hi,
>
> I'd add to what Bocean said and add a progress field to the table so
> you know if the script is still running or has completed its
> operations. The Field can simple state in-progress or completed with
> the date-time.
>
> Sincerely,
> Mike
> -- 
> Mike Brandonisio          *    Web Hosting
> Tech One Illustration     *    Internet Marketing
> tel (630) 759-9283        *    e-Commerce
> [EMAIL PROTECTED]    *    http://www.jikometrix.net
>
>      JIKOmetrix - Reliable web hosting
>
>
> On Nov 23, 2006, at 12:37 AM, Mark Wheeler wrote:
>
>> Hi,
>>
>> I have a script that takes a long time (20 minutes, or so) to perform
>> (sending email out) and I'm afraid that the browser is timing out, so
>> I thought I would reload the windows with a progress script. After
>> starting the script, if I close the browser window or reload it, does
>> the original script keep going until it's finished, or does the
>> browser send a message to the server telling it to stop execution of
>> the script? The reason for asking is I'd like to start sending email,
>> but would then like to load that window with an update script that
>> checks and displays the process.
>>
>> Thanks,
>>
>> Mark
>>
>>
>> The php_mysql group is dedicated to learn more about the PHP/MySQL
>> web database possibilities through group learning.
>> Yahoo! Groups Links
>>
>>
>>
>>
>
>
>
> The php_mysql group is dedicated to learn more about the PHP/MySQL  
> web database possibilities through group learning.
> Yahoo! Groups Links
>
>
>
>

Reply via email to