#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Posts
    7
    Rep Power
    0
    Greetings!

    I have a problem when I try to send a email to recipients that i have in a mySQL table...

    With a 33 entries in the table i only can send the email to 10 people.

    Can someone help me with this timeout of the mail() function???

    My code is:

    :code:
    $send_query = "SELECT codemember, email FROM members WHERE codelist=$code";
    $result = mysql_query($send_query);


    if ($affected_rows = mysql_affected_rows()){

    while ($row = mysql_fetch_row($result)){
    $codmember = $row[0];
    $toemail = $row[1];

    if ( mail($toemail,$Subject,$Body,"From:$FromnReply-To: $From") ) $resultado = "Sent";
    else $resultado = "Not sent";

    }

    :code:

    Please Help I am very confused

    Valter
  2. #2
  3. .Net Developer
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2000
    Location
    London
    Posts
    987
    Rep Power
    15

    $send_query = "SELECT codemember, email FROM members WHERE codelist=$code";
    $result = mysql_query($send_query);


    if ($affected_rows = mysql_affected_rows()){

    while ($row = mysql_fetch_row($result)){
    $codmember = $row[0];
    $toemail = $row[1];

    if ( mail($toemail,$Subject,$Body,"From:$FromnReply-To: $From") ) $resultado = "Sent";
    else $resultado = "Not sent";

    }



    Why are you using this "if ($affected_rows = mysql_affected_rows()){".?


    No need to write that line ..

    Try this..


    $send_query = "SELECT codemember, email FROM members WHERE codelist=$code";

    $result = mysql_query($send_query);

    if (mysql_num_rows($result)>0){
    //you have some mails to send..

    while ($row = mysql_fetch_row($result)){
    $codmember = $row[0];
    $toemail = $row[1];
    mail($toemail,$Subject,$Body,"From:$FromnReply-To: $From");
    }
    echo "Mail has been sentn";
    }else{
    //No records

    echo "No Recordsn";
    exit;
    }





    ------------------
    SR -
    webshiju.com

    "The fear of the LORD is the beginning of knowledge..."
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Posts
    7
    Rep Power
    0
    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">quote:</font><HR>Originally posted by Shiju Rajan:
    [b]

    Why are you using this "if ($affected_rows = mysql_affected_rows()){".?


    No need to write that line ..

    Try this..


    $send_query = "SELECT codemember, email FROM members WHERE codelist=$code";

    $result = mysql_query($send_query);

    if (mysql_num_rows($result)>0){
    //you have some mails to send..

    while ($row = mysql_fetch_row($result)){
    $codmember = $row[0];
    $toemail = $row[1];
    mail($toemail,$Subject,$Body,"From:$FromnReply-To: $From");
    }
    echo "Mail has been sentn";
    }else{
    //No records

    echo "No Recordsn";
    exit;
    }


    [/quote]


    Thanks Shiju Rajan for your reply, but i still get the same time out problem with mail()

    Valter

  6. #4
  7. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Location
    Cardiff
    Posts
    9
    Rep Power
    0
    Try

    set_time_limit(0);

    Before you start your loop. Otherwise, try

    set_time_limit(50);

    inside the loop, before each post. You might also want to look up the ignore_user_abort() function in the php manual (www.php.net) - it's a handy function to call when sending out loads of emails.

    Dan
  8. #5
  9. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Posts
    7
    Rep Power
    0
    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">quote:</font><HR>Originally posted by spxdcz:
    Try

    set_time_limit(0);

    Before you start your loop. Otherwise, try

    set_time_limit(50);

    inside the loop, before each post. You might also want to look up the ignore_user_abort() function in the php manual (www.php.net) - it's a handy function to call when sending out loads of emails.

    Dan
    [/quote]


    Thanks a lot Dan. But I try the two methods and i still can't send messages to more than 40 email when I want to send to over 2000...

    I get this error after the 30-40 mail() call:

    Warning: Failed to Connect in modules/message.php on line 85


    Pleeeeaaaseee! I need Help

    Valter
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Posts
    45
    Rep Power
    14
    Sorry, I can't give you an exact solution but I do know what's going on.

    What's happeneing is that PHP has a built in counter to stop an infinite loop from going on forever. It times the loop and as soon as it goes on for a certain amount of time, it stops. This creates a problem when you're using mail, because it could take a while for the loop to complete, but PHP doesn't know that - it thinks it's an infinite loop so it stops the loop (hope I explained that well).

    One solution posed is that you have a counter variable, and you only send out 10 emails per page, and once the 10 emails are sent, you increase the counter, and refresh the page. I haven't actually done this - there are scripts out there for mass mailings, and this topic has been broached in this forum before - try searching. Hope that helped you a little, even if it didn't give you the solution.

Similar Threads

  1. Uploading Files
    By vivekjain in forum ASP Programming
    Replies: 0
    Last Post: February 16th, 2004, 11:21 PM
  2. Replies: 5
    Last Post: February 11th, 2004, 02:18 AM
  3. Replies: 0
    Last Post: February 10th, 2004, 11:44 PM
  4. Help with script
    By akastarlight in forum Perl Programming
    Replies: 1
    Last Post: February 6th, 2004, 06:55 AM
  5. Replies: 1
    Last Post: January 30th, 2004, 06:04 PM

IMN logo majestic logo threadwatch logo seochat tools logo