views:

72

answers:

3

i have following variables in jquery

var uemail="[email protected],[email protected],[email protected]";
var subj="test message";
var text="<b>This is Email Body Text</b>";

i have one PHP file named "email.php" to send email

<?php

      $email =$_GET['email'];
      $subject =$_GET['subj'];
      $message = $_GET['text'];;

     if(mail($email, $subject, $message, "From: $email"))
     echo "1";
     else
     echo "0";
?>

what i want to do is

call email.php for number of time i have email address in variable uemail and each time pass email,subj,text to email.php and print result on page that with 10 Sec interval Between each time email.php called.

[email protected] (ok)
[email protected] (Error)
[email protected] (ok)

Thanks

+2  A: 

I think you want a line like this in your javascript: setInterval(function() {$.ajax{url:'url of emails.php'};}, 10000);

That will make an ajax request to the php page every 10000 miliseconds.

monksp
+4  A: 
var n = 1;
$.each(uemail.split(','), function() {
    var data = {email: this.valueOf(), subj: subj, text: text};

    setTimeout(function() {
        $.post('http://.../email.php', data, function(resp) {
            alert(data.email + (resp ? 'ok' : 'error'));
        });
    }, n++ * 10000);
});

This way you won't have to take care about stopping the interval.

aefxx
+1  A: 

Here's an alternate approach if you don't want multiple timers running parallel.

    var uemail="[email protected],[email protected],[email protected]";

    uemail = uemail.split(',');

    var interval;
    var counter = 0;
    var check = function() { 
                            if(counter < uemail.length) {
                                // Send email post 
                                counter++; 
                            } else {
                                clearInterval(interval);
                            }
                };

    interval = setInterval(check,10000);
patrick dw