user195257
user195257

Reputation: 3316

send over 100 with mail()

I have just over 100 contacts i need to e-mail to

while ($row = mysql_fetch_array($result)){  

    $message = "Hello ".$row['first_name'].", \r\n";
    $message = $message.$_POST['message'];

        if (mail($row['email_address'], $subject, $message, $headers)){
            $sent ++;
        }else{
            $error ++;
        }
    }

Will this run okay? I have looked at other methods (pear, smtp) but wondering if this will run okay?

Thanks

Upvotes: 1

Views: 440

Answers (4)

Peter Porfy
Peter Porfy

Reputation: 9030

Use sleep(int secs) or usleep(int microseconds) for time delay.

You should use usleep for small delays at loop end in every cycle, or you sleep after every 10 mail for example. Depends on your mail server capacity.

Upvotes: 2

Toon Krijthe
Toon Krijthe

Reputation: 53366

I have recently used the mail function to send to over 100 recipients. So yes it will work.

There where some problems with the function, but a slight delay (100ms) between the mail calls helped solve that problem.

Upvotes: 3

b_erb
b_erb

Reputation: 21241

If you are not aware that your mail server will handle the number, you can split up the work into smaller groups of addresses and add them to a temporary storage (ie. MySQL table).

Then on each page request, you can get some addresses, send the messages and remove them from the temporary table.

Upvotes: 0

Pekka
Pekka

Reputation: 449385

That will very much depend on your server configuration and a possible "max number of E-Mails per x" limit imposed by your provider. Mail() is not the perfect command for bulk mail but out of general experience I would say that anything up to a few hundred mails is likely to work fine.

Remember to log addresses for which sending fails straight away (possibly due to such a limitation), and setting up a bounce address for the rest.

Upvotes: 2

Related Questions