1

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

1
  • @Natrium - What don't you understand about this question? Commented Mar 2, 2010 at 13:10

3 Answers 3

4
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.

Sign up to request clarification or add additional context in comments.

Comments

2

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.

Comments

1

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);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.