I'm trying to track down an odd problem in a script I'm writing, the 
purpose of which is below:

The script takes data of a subject and a body for an e-mail from an HTML 
form, and sends this out to a list of recipients stored in a datafile 
parsed by the PHP.  The size of the e-mails can be quite large (~100kb, 
all text), and this can be required to be sent to ~400 users.

Currently, we have a problem in that when sending a mail of 
approximately 70kb text, it will not complete - after approximately 2 
minutes, it gives an Internal Server Error (not a php error) and fails. 
  In this time, it has sent out approximately 25 messages.  This speed 
wouldn't be too much of an issue, if it would send to all 400 people on 
the list!

The PHP can be found below - I'm already resetting the set_time_limit on 
each loop execution, so as I understand it the script should happily run 
for as long as necessary.  We do not have access to configure the PHP 
installation on the server (running 4.1.2)

Code follows - I hasten to add that this appears to work admirably on 
small lists.

   if($file = fopen($list, "r"))
      // Initialise variable
      $counter = 0;

      // Repeat until end-of-file reached.
         // Open link to sendmail program with write permissions - assign
         // reference to $mailout
        $mailout = popen("/usr/sbin/sendmail -t -i","w");
        // Set address variable to next line of datafile, up to a
         // maximum length of 255 characters.
        // This assigns the $address variable the next address from the
         // data file on each loop of the
         // while statement.
        $address = fgets($file, 255);

        // Write out to sendmail the correct information.
        fputs($mailout, "To: $address \n");
        fputs($mailout, "From: Sender <[EMAIL PROTECTED]>\n");

        // $subject and $body are passed from the html form page - these
         // are the names of the form elements.
        fputs($mailout, "Subject: $subject\n");

        // Send top of body out
        fputs($mailout, "header goes here\n");

        // Send out user-entered body
        fputs($mailout, "$body\n");

        // Send bottom of body out - need escape characters if using
         // reserved characters (like ")
        fputs($mailout, "foot goes here\n");

        // Tidy up and close sendmail link - this needs to be done on
         // each loop, otherwise seperate e-mails
        // not generated.

        // Reset PHP timeout.

        // Increment counter of e-mail messages sent.
        $counter = $counter + 1;


      // Tidy up and close the datafile.

      // Print out confirmation of send
      print("Message successfully sent to $counter recipients from the 

Any help gratefully appreciated,


PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to