使用jQuery和PHP的电子邮件脚本

I am writing one script to send bulk emails....

  1. Where user will select multiple lists from multi select list box.

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

  1. Get number of lists
  2. Get emails from one list (ALL emails if possible or 1000 each time from list) and send them emails
  3. Again get emails from other selected list and send emails.
  4. Each emails will send to sendmails.php and after processing this will return success or error and append in page and then nest email address will be send.

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.