adhbvklwqdbviabjiawdnbij Posted September 24, 2011 Share Posted September 24, 2011 Is there anything I should change on this code? I'll use it to send about 20000 emails... I don't like this one, because while sending the emails, the page keep loading... I kind dont "trust" on this script.. index.php <?php include('config.php'); include('class.phpmailer.php'); include('email.php'); // Get users info $getUser_sql_not_sent = "SELECT * FROM emails WHERE sent = '0'"; $getUser_not_sent = mysql_query($getUser_sql_not_sent); $getUser_num_not_sent = mysql_num_rows($getUser_not_sent); $getUser_sql_sent = "SELECT * FROM emails WHERE sent = '1'"; $getUser_sent = mysql_query($getUser_sql_sent); $getUser_num_sent = mysql_num_rows($getUser_sent); $getUser_sql_all = "SELECT * FROM emails"; $getUser_all = mysql_query($getUser_sql_all); $getUser_num_all = mysql_num_rows($getUser_all); $getUser_sql_accessed = "SELECT * FROM emails WHERE accessed = '1'"; $getUser_accessed = mysql_query($getUser_sql_accessed); $getUser_num_accessed = mysql_num_rows($getUser_accessed); $money = $getUser_num_accessed * 0.20; $money_formated = number_format($money, 2, ',', ''); $x = $getUser_num_sent * 100; $y = $getUser_num_all; $percentage = $x / $y; $percentage_formated = number_format($percentage, 0, '', ''); if ($getUser_num_not_sent == $getUser_num_all) { echo '<form action = "send.php" method = "post">'; echo '<strong>Assunto do Email</strong><br />'; echo $emailSubject; echo '<br />'; echo '<strong>Corpo do Email</strong><br />'; echo $emailBody; echo '<br /><br />'; echo '<input name = "send" type = "submit" value = "Enviar Emails" />'; echo '</form>'; } else { echo "Foram enviados " . $percentage_formated . "% dos emails. " . $getUser_num_accessed . " acessaram o site, bonificação de R$ " . $money_formated . " para o Claudius Ibn."; } ?> <?php include('config.php'); include('class.phpmailer.php'); include('email.php'); echo 'Os emails estao sendo enviados, voce pode sair do site que o processo continuara mesmo assim.'; // Get users info $getUser_sql_not_sent = "SELECT * FROM emails WHERE sent = '0'"; $getUser_not_sent = mysql_query($getUser_sql_not_sent); $getUser_num_not_sent = mysql_num_rows($getUser_not_sent); $mail = new PHPMailer(); while ($row = mysql_fetch_array($getUser_not_sent)) { // Get the current user's email $emailUser = $row['email']; // Define mail object and mail parameters $mail -> From = '[email protected]'; $mail -> FromName = 'Campainha'; $mail -> AddAddress($emailUser); $mail -> Subject = $emailSubject; $mail -> Body = $emailBody; // Send and verify if(!$mail -> Send()) { echo 'Erro: '. $mail -> ErrorInfo; } else { mysql_query("UPDATE emails SET sent = '1' WHERE email = '$emailUser'"); } sleep(30); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/247757-newsletter/ Share on other sites More sharing options...
Freedom-n-Democrazy Posted September 24, 2011 Share Posted September 24, 2011 There is a good book on Amazon you should check out. http://www.amazon.com/Wicked-Cool-PHP-Real-World-Difficult/dp/1593271735/ref=sr_1_1?s=books&ie=UTF8&qid=1316837912&sr=1-1 Quote Link to comment https://forums.phpfreaks.com/topic/247757-newsletter/#findComment-1272261 Share on other sites More sharing options...
adhbvklwqdbviabjiawdnbij Posted September 24, 2011 Author Share Posted September 24, 2011 Thanks... How can i make the script run in "background"? How can i make the script send 10 email every 30 seconds? Quote Link to comment https://forums.phpfreaks.com/topic/247757-newsletter/#findComment-1272338 Share on other sites More sharing options...
Freedom-n-Democrazy Posted September 24, 2011 Share Posted September 24, 2011 With this: http://php.net/manual/en/function.sleep.php Quote Link to comment https://forums.phpfreaks.com/topic/247757-newsletter/#findComment-1272364 Share on other sites More sharing options...
adhbvklwqdbviabjiawdnbij Posted September 24, 2011 Author Share Posted September 24, 2011 Ok, i know how to send one email every 30 seconds, but how to send 10 emails every 30 seconds? Quote Link to comment https://forums.phpfreaks.com/topic/247757-newsletter/#findComment-1272368 Share on other sites More sharing options...
Freedom-n-Democrazy Posted September 24, 2011 Share Posted September 24, 2011 Could you please post your solution so others may benefit from it. Quote Link to comment https://forums.phpfreaks.com/topic/247757-newsletter/#findComment-1272384 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.