mail() usage in for loops
| From: | Mohanaraj | Date: | Sat, 09 Aug 2003 04:47:46 +0000 |
| Subject: | mail() usage in for loops | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-158976@lists.php.net to get a copy of this message | ||
Dear all,
I have read that using mail() in a for loop to send a lot of emails (
around 1k-10k ) emails is not advised due to the fact that it can be
resource intensive hence or the script might take so much time that it
ti,es out. However what if i append all the emails into the Bcc: header
as follows and make only 1 call to mail.
1. Is this better?
2.Will it still be resource hungry?
3.What would be the best way to handle mailing to many email addresses
from PHP. This is for a newsletter (not SPAM) application I am working on.
4.How does this compare against using sockets to directly speak to the
SMTP server from a efficiency aspect?
The code I am planning on using (which I got online too ) is as follows :
$email = "test@test.com";
$subject = "test";
$body = "This is a test.";
$headers = "From: test@test.com\n";
$headers .= "Reply-to: noreply@mydomain.com\n";
//the following willl have all the email addresses which will receive
the email
$headers .= "Bcc: test0@test.com\n";
$headers .= "Bcc: test1@test.com\n";
$headers .= "Bcc: test2@test.com\n";
$headers .= "Bcc: test3@test.com\n";
$headers .= "Bcc: test4@test.com\n";
//..and so on...
$headers .= "Content-Type: text/plain; charset=iso-8859-1\n";
mail ($email, $subject, $body, $headers);