0

I am trying to send email to a large list of contacts and i want to be able to measure the degree of sending i.e that is display a loading bar that shows the percentage of sending while email is being sent. below is the html

<div id="loading" style="height:20px;"></div>

Then the Javascript code

$.ajax({
    type: "POST",
    url: "engine/send-mail.php",
    data: "action=sendmail",
    success: function (Databack) {
        $('#loading').css('width', Databack);
    }
});

note the php server side code

$query = "SELECT email FROM clientsdata";
while ($data = mysql_fetch_array($query)) {
    extract($data);
    mail_user($email, $subject, $message);
    $no++;
    echo $no."px;";
}

more like a progress bar but it dont work.

Jaak Kütt
  • 2,566
  • 4
  • 31
  • 39
Udo
  • 1,129
  • 3
  • 15
  • 30

5 Answers5

0

You won't be able to do it that way, since your php will only respond when the script will end.

What you can do is link an ID to each email of your database, so after that you will be able to loop through an array of UID in javascript to chain ajax calls.

y_nk
  • 2,157
  • 2
  • 19
  • 29
0

There are a lot of PHP classes you can play with to update a visual progress bar in your web page.

For example : http://www.m4d3l-network.com/developpement/php/simple-progress-bar/

Zend Framezork embeds this functionality BTW.

sdespont
  • 13,915
  • 9
  • 56
  • 97
0

Take a look at this post about displaying ajax with jQuery as the data comes in.

Community
  • 1
  • 1
0

You can query eg. 40 email addresses instead of all. Then call you email script multiple times, and with each ajax call you send the next 40 emails... so you can set up a progess bar very easy. Maybe create a email queue in your db with all emails to send, and each ajax call deletes the sent emails from the queue.

Ilyssis
  • 4,849
  • 7
  • 24
  • 30
-1

You need an asynchronous request. There are several ways to do this, like long polling or Web Sockets. I am not sure if there are any frameworks around, but this posting seems to be relavent.

Community
  • 1
  • 1
CodeChimp
  • 8,016
  • 5
  • 41
  • 79