1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

PHP - Delay function - please help

Discussion in 'PHP' started by crizatu, Jan 23, 2006.

  1. #1
    Hello, I have a small script to send the content of a form to 2 different email adesses. The problem is that because of the server restriction, the server only sends 1 email in a 10 seconds time frame. Could you tell me how can I make a pause/delay in php?

    sorry for my english and thank you in advance,
    Adrian
     
    crizatu, Jan 23, 2006 IP
  2. digitalpoint

    digitalpoint Overlord of no one Staff

    Messages:
    38,333
    Likes Received:
    2,613
    Best Answers:
    462
    Trophy Points:
    710
    Digital Goods:
    29
    #2
    digitalpoint, Jan 23, 2006 IP
  3. crizatu

    crizatu Well-Known Member

    Messages:
    465
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    135
    #3
    Thank you, this works great
     
    crizatu, Jan 23, 2006 IP
  4. yangyang

    yangyang Banned

    Messages:
    757
    Likes Received:
    26
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Shawn's right. Use sleep(12) or something like this to pause the php execution for 12 seconds before sending the next email.

    However there's also a chance that if you have 2 scripts sending emails, one of them may fall into the time frame, failing to send the message. Consider, script 1 sends an email at 080000, waiting for 12 seconds before sending the other, however, at 080006 (6 seconds later), script 2 sends an email and will fail.

    The solution is to check if mail() returns true, if it does not, keep trying it with 12 seconds interval until it does. And it's after a confirmed successful delivery, you continue with the rest logic.
     
    yangyang, Jan 1, 2009 IP
  5. improvingtheweb

    improvingtheweb Peon

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    You can send one email to multiple recipients with the mail function, which should work even under your server restrictions.

    
    <?php
    $to  = 'user1@example.com, user2@example.com';
    
    $subject   = 'Test';
    $message = 'Test';
    
    mail($to, $subject, $message);
    ?>
    
    Code (markup):
     
    improvingtheweb, Jan 1, 2009 IP
  6. Danltn

    Danltn Well-Known Member

    Messages:
    679
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    120
    #6
    Just FYI, but this thread is 3 years old...
     
    Danltn, Jan 1, 2009 IP
  7. juust

    juust Peon

    Messages:
    214
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Still, the thread is interesting. Sending the same post to two receivers works better but it doesn't solve the problem. locking the file might prevent people from sending whilst one routine is 'waiting'. Queueing messages and having a separate cronjob send messages would work even better, and the best solution is finding a proper host.
     
    juust, Jan 1, 2009 IP
  8. maxdevelopers

    maxdevelopers Guest

    Messages:
    52
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    How do I send information back and forth in PHP?
     
    maxdevelopers, Mar 16, 2009 IP
  9. SmallPotatoes

    SmallPotatoes Peon

    Messages:
    1,321
    Likes Received:
    41
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Back and forth from where to where?
     
    SmallPotatoes, Mar 16, 2009 IP