Thread: getting 500 internet server error while using php email

Results 1 to 6 of 6
  1. #1 getting 500 internet server error while using php email 
    Registered Member
    Join Date
    May 2015
    Posts
    1
    Thanks given
    0
    Thanks received
    0
    Rep Power
    0
    Hi, i want to send email to my 600 clients through php email. but the loop works till 20 contacts, after that it show 500 internal server error. I am using hostforlife server. Here is the script:
    <?php
    for($x=1;$x<=600;$x++)
    {
    $con = mysqli_connect("host","database","password");
    if (!$con){die('Could not connect: ' . mysqli_error($con));}
    mysqli_select_db($con,"database");
    $sql="SELECT email FROM emails Where id = ".$x;
    $result = mysqli_query($con,$sql);
    $row = mysqli_fetch_array($result);
    $to = $row['email'];
    if ($to == "NULL")
    {

    }
    else
    {
    echo $row['email'];
    mysqli_close($con);
    // mail($to,"subject","message");
    sleep(2);
    }
    }
    ?>
    Reply With Quote  
     

  2. #2  
    Registered Member

    Join Date
    Dec 2011
    Posts
    1,615
    Thanks given
    1,971
    Thanks received
    819
    Rep Power
    1049
    Code:
    	error_reporting(E_ALL ^ E_NOTICE);
    	ini_set('display_errors', TRUE);
    	ini_set('display_startup_errors', TRUE);
    Put this at the very top of your main file. See if it outputs any problems. Alternatively, check the web server error.log, if you post it here I'll see if there's anything that stands out.
    Reply With Quote  
     

  3. #3  
    Registered Member
    Anthony`'s Avatar
    Join Date
    Sep 2008
    Age
    29
    Posts
    763
    Thanks given
    75
    Thanks received
    164
    Rep Power
    204
    Well for starters it would probably be smart not to open 600 database connections. Instead, just open one connection, and instead of querying for one person at a time, just query the entire table (remove the WHERE clause) and iterate through that result set.
    Reply With Quote  
     

  4. Thankful users:


  5. #4  
    Registered Member
    Join Date
    Oct 2014
    Posts
    122
    Thanks given
    101
    Thanks received
    39
    Rep Power
    44
    Quote Originally Posted by Anthony` View Post
    Well for starters it would probably be smart not to open 600 database connections. Instead, just open one connection, and instead of querying for one person at a time, just query the entire table (remove the WHERE clause) and iterate through that result set.
    /thread
    I came here to promote my lwjgl morpg, but no, 90% of you are neanderthals and this forum is weird. Glad I realized it before I finished my project because I sure don't want a bunch of flaming boneheads coming to my community
    Reply With Quote  
     

  6. #5  
    Registered Member

    Join Date
    Dec 2011
    Posts
    1,615
    Thanks given
    1,971
    Thanks received
    819
    Rep Power
    1049
    Quote Originally Posted by Anthony` View Post
    Well for starters it would probably be smart not to open 600 database connections. Instead, just open one connection, and instead of querying for one person at a time, just query the entire table (remove the WHERE clause) and iterate through that result set.
    Would have actually read the code if it was in the code tags Props to you for reading that crap.
    Reply With Quote  
     

  7. #6  
    Registered Member MDev's Avatar
    Join Date
    Apr 2015
    Age
    30
    Posts
    108
    Thanks given
    21
    Thanks received
    11
    Rep Power
    6
    And instead of using a for loop, query the database first and use the while loop with your resultset to mail to the users.
    Ex:
    Code:
    if ($result = $mysqli->query($query)) {
    
        /* fetch associative array */
        while ($row = $result->fetch_assoc()) {
            //Email to $row['email'];
        }
    
        /* free result set */
        $result->free();
    }
    (from mysqli documentation @ PHP website)
    Reply With Quote  
     


Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. PI - Server Error While Running?
    By Star Pker in forum Help
    Replies: 3
    Last Post: 02-06-2012, 02:22 AM
  2. Replies: 1
    Last Post: 01-19-2012, 01:35 PM
  3. 500 Internal Server Error
    By Dexter Morgan in forum Forum Related Help
    Replies: 8
    Last Post: 12-22-2009, 11:53 PM
  4. 500 Internal Server Error
    By Swarfega in forum Forum Related Help
    Replies: 4
    Last Post: 11-07-2009, 04:30 PM
  5. 500 Internal Server Error
    By Scu11 in forum Forum Related Help
    Replies: 0
    Last Post: 11-07-2009, 03:43 PM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •