SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Hybrid View

  1. #1
    SitePoint Enthusiast
    Join Date
    Jan 2008
    Posts
    62
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    have a working email for that I need to loop every 10 seconds

    I have a working emial form below thatsubmits to one person on the list of students. I was told to loop the emails thru and tohaveit sleep for 10sec before it loops the next email through. That is were I have the problem I do not know how to do that. I have tryied for about 2 weeks know and it is driving me crazy.

    Below isthe working email code that only sends to one person.

    PHP Code:

        
    if ($_POST['submit'] == TRUE)  {

          
    $receiverMail "$title1, ";

        
    $namestripslashes(strip_tags($_POST['Name']));

        
    $subjectstripslashes(strip_tags($_POST['subject']));

        
    $emailstripslashes(strip_tags($_POST['Email']));

        
    $Cphonestripslashes(strip_tags($_POST['Contact_Number']));

        
    $contactstripslashes(strip_tags($_POST['Comment']));

        
    $ip$_SERVER['REMOTE_ADDR'];

        
    $msgformat    "From: $name \nEmail: $email\nContact_Number: $Cphone\n\nComment: $contact";


        if(empty(
    $name) || empty($email)) {

            echo 
    "<h2 style='font-family:Georgia;;background-color:#fa9283;font-weight:bold;'><center>* &nbsp;* &nbsp;The email was NOT sent!&nbsp; *&nbsp; *</h2><br><br><h3><center>* &nbsp;* &nbsp;Please fill all the required fields&nbsp; *&nbsp; *</h3><br><br>";

        }

        elseif(!
    ereg("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$"$email)) {

            echo 
    "<h2 style='font-family:Georgia;;background-color:#fa9283;font-weight:bold;'><center>* &nbsp;* &nbsp;The email was NOT sent!&nbsp; *&nbsp; *</h2><br><br><h3><center>* &nbsp;* &nbsp;The email address is invalid&nbsp; *&nbsp; *</h3><br><br>";

        }

        elseif(
    mail($receiverMail$subject$msgformat"From: $name <$email>")) {

            echo 
    "<h2 style='font-family:Georgia;;background-color:#acd8f9;font-weight:bold;'><center>* Your Information has been sent! *</h2><br><br><h3><center>Your mail has been sent to Your Class List <u>Thank You</u>!</h3><br><br>"; }

        else {

            echo 
    "<h2 style='font-family:Georgia;;background-color:#fa9283;font-weight:bold;'><center>* &nbsp;* &nbsp;The email was NOT sent!&nbsp; *&nbsp; *</h2><br><br><h3><center>Please try again... If the problem continues there's probably something wrong with the server.</h3><br><br>";

        }

    }

    echo 
    "<form enctype='multipart/form-data' method='post' action=''>";
    echo 
    "<input type=hidden name='subject' value='News form Karate Club'>";
    echo 
    "<table width='440' align='left'><tr>";
    echo 
    "<td><font size='3' color='#990000'>Name:</td><td><input type=text id='Name' name='Name' size='25'></td>";
    echo 
    "</tr><tr>";
    echo 
    "<td><font size='3' color='#990000'>Email:</td><td><input type=text id='Email' name='Email' size='25'></td>";
    echo 
    "</tr><tr>";  
    echo 
    "<td><font size='3' color='#990000'>Phone:</td><td><input type=text id='Contact_Number' name='Contact_Number' size='15'></td>";
    echo 
    "</tr><tr>";
    echo 
    "<td><font size='3' color='#990000'>Comment:</td><td><textarea cols='32' rows='8' name='Comment' id='Comment' size>";
    echo 
    "</textarea></td>";
    echo 
    "</tr><tr>";
    echo 
    "<input id='submit' type='submit' name='submit' value='Submit to Student List'></center><br>";
    echo 
    "</td></tr></table>";
    echo 
    "</form>"
    this bit of code is what needs to be looped

    PHP Code:
        $receiverMail "$title1, "
    the $title1 var comes from earlier in the page wher I pull info to list the name and email address next to the form so the instructor can see who they are mailing. the code is below.

    PHP Code:

    $count 
    $s ;

    // now you can display the results returned

      
    while ($rowmysql_fetch_array($result)) {

      
    $title $row["Name"];

      
    $title1 $row["Email"];

      echo 
    "<tr><td width='170'>$title</td><td width='170'>$title1</td></tr>";

      
    $count++ ;

      }

    echo 
    "</table>"
    that list all the emails in order one under each other. When I put it into the code I added a space and a comma so to seperate each email buy so to send it in bulk but there was a problem with a not working and b viewing as spam. I was told to do one every 10 seconds so that youwill not go past your server quota incase I send to the whole school of over a thousand. I was given the code

    PHP Code:
    sleep (10
    to putin and allow it to pause for 10 seconds then resubmit the next looped email email. That is where the problem is I have no idea how to do that.

    PLEASE ADVISE, need to know how to loop through the database and email every 10 seconds the next student ??????

  2. #2
    SitePoint Enthusiast
    Join Date
    Jun 2008
    Posts
    62
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    why don't you use a cron job for this? that's what i've done in the past.

  3. #3
    SitePoint Enthusiast
    Join Date
    Jan 2008
    Posts
    62
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have heard of this before and have no idea where to begin or what that is in reference to

  4. #4
    SitePoint Enthusiast
    Join Date
    Apr 2009
    Location
    Ljubljana, Slovenia
    Posts
    36
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    doing sleep (10) on the server is a bad idea. Cron is a good idea, but how do we stop it after last mail?
    I had a similar problem parsing stock market charts, that were to big to handle in one request.
    This is what I've done:
    - there should be some logic by id, status or timestamp in db of the mails that were already send.
    - I'd send an 1 email and posting data to a page with some hidden field having status 1 or next
    - I'd then make a JavaScript code that waits for 10sec and post form back if a value is 1
    - Then I'd change posted value to 0 if no mails are left to send

    The point here is that server doesn't hold your request for nothing and it's free to do some other job. There are also some time and mem limitations that should be changed in your php.ini, if you'd choose to do it in 1 request.
    Gregor Grajzar, web developer
    http://xweblabs.com
    http://grajzar.info


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •