I am writing one script to send bulk emails....
After selecting list it start sending emails to all emails in that list, in one list emails can be up to 100,000.
<select name='lists' id='lists' multiple='multiple' class='multiselect' >
<?php
$sql="select list_id,list_name from tbl_list" ;
$result=mysql_query($sql);
for($i=1;$i<=mysql_num_rows($result);$i++)
{
$row=mysql_fetch_array($result);
?>
<option value='<?php echo $row['list_id']; ?>' title='<?php echo $row['list_name']; ?>'><?php echo $row['list_name']; ?></option>
<?php
}
?>
</select>
Now after selecting the lists I have following jquery:
var listsValues = $("#lists").val()
var n = 1;
$.each(listsValues, function() {
var data= {list_id:encodeURIComponent(listsValues[n-1])};
setTimeout(function() {
$.post('GeteTmails.php', data, function(resp) {
//////// to bring 1000 emails at one me/////////////////
var Totalemails=resp;
var Totalsteps=Math.round(Totalemails/1000)+1;
for($i=1;$i<=Totalsteps;$i++)
{
start=($i-1)*1000;
limit=$i*1000;
$.ajax({
type: "POST",
url: "getemails.php",
cache:false,
data:"list_id="+ encodeURIComponent(listsValues[$i-1])+"&start="+start+"&limit="+limit,
dataType:'json',
success: function(json)
{
var foo = json.foo;
//////////// send emails ///////////////////////////
uemail = foo.split(',');
var interval;
var counter = 0;
var ecounter=1;
var check = function() {
if(counter < uemail.length) {
$("#sending_count").html("Sending Message "+ ecounter +" of " + uemail.length);
var data = {email: uemail[counter], subj: email_subject,r_rec:r_rec,temp_id:temp_id,email_message:email_message,msgid:msgids[0]};
$.ajax({
async: false,
type: "POST",
url: "sendmails.php",
data:data ,
success: function(html){
$("<div>"+ html +"</div>").appendTo("div#meprocess");
}
});
counter++;
ecounter++;
} else {
clearInterval(interval);
$("#sending_process").html("Email Sending Complete");
//alert('done');
}
};
interval = setInterval(check,5000);
///////////////////////////////////////////////////////////////////////////////////////
}
});
}
//////////////////////////////////////////////
});
}, n++ * 1000);
});
Its not working properly...
I am using interval otherwise script go logoff and remove session.
Basic thinking behind this is like that
In get email if possible it can be all emails in one time but as I mention it can be 100,00 emails and its not returning that much data, so it can be 1000 emails in each cycle.