Re: Odd problem using sendmail - possibly to do with set_time_limit?
| From: | Jon Abernathy | Date: | Wed, 06 Mar 2002 00:07:41 +0000 |
| Subject: | Re: Odd problem using sendmail - possibly to do with set_time_limit? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-87380@lists.php.net to get a copy of this message | ||
"Alexis Birkill" <csvax@warwick.ac.uk> wrote in message
news:3C8407C5.1080105@warwick.ac.uk...
> Hi,
>
> I'm trying to track down an odd problem in a script I'm writing, the
> purpose of which is below:
>
<snippage>
>
> 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.
After reviewing your code, I was wondering if there was a reason you aren't
using PHP's built-in mail() function, rather that using popen() and a series
of fputs(), which seems rather expensive, especially inside of a loop. Also,
you only need to use set_time_limit() once, outside of your loop-- pass 0 as
the parameter, which basically turns off the timeout.
Here's how I would code this:
$counter = 0;
set_time_limit(0);
if ( $fp = fopen($list, 'r') ) {
while ( $address = fgets($fp, 255) ) {
mail( $address, $subject, "header goes here\n$body\nfoot goes
here\n", "From: Sender <sender@domain.com>\n" );
$counter++;
}
fclose( $fp );
print("Message successfully sent to $counter recipients from the
$list");
}
Hope this helps.
--
Jon Abernathy - jon@alpineinternet.com
Alpine Internet Solutions - www.alpineinternet.com