Re: Odd problem using sendmail - possibly to do with set_time_limit?

From: Date: Wed, 06 Mar 2002 10:56:22 +0000
Subject: Re: Odd problem using sendmail - possibly to do with set_time_limit?
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-87446@lists.php.net to get a copy of this message
Jon Abernathy wrote:
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,
Sounds like a much better idea, looking at the mail() function. I'm more familiar with using sendmail etc., so I gravitated towards that - I should have examined my options more thoroughly.
you only need to use set_time_limit() once, outside of your loop-- pass 0 as the parameter, which basically turns off the timeout.
Ahh, really. That's interesting - I'd assumed that this wouldn't work as it would allow a badly-written script to get itself into some kind of infinite loop easier - but I'm sure you're right.
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");
    }
Much more concise - thanks.
Hope this helps.
Indeed it does - thank you (again) very much! A.

« previous php.general (#87446) next »