PDA

View Full Version : Mass Emailing with mail() Function


PHPGuru
1-30-04, 01:02 AM
Let's say that you have a script to send e-mails using mail() function. You send out one e-mail at a time using the function in the loop. When you are done, you finish.

+++++++++++++++++++++++++++++++++++++++++++++
ex. (to get the idea, not the actual working script)

$email_address_list = array of maybe 1000 e-mail addresses.

for ($i = 0; $i < sizeof($email_address_list); $i++)
{
mail($email_address[$i], "subject", "body", "header");
}

print a message that the mail was sent to all 1000 e-mail addresses.
+++++++++++++++++++++++++++++++++++++++++++++

Now, here is the question:

How many e-mails can you possibly send using mail() in the loop before you get a timeout problem?? If there is a limitation, then is there a way to work around with this thing??

Mirzabah
1-30-04, 01:10 AM
Originally posted by PHPGuru
How many e-mails can you possibly send using mail() in the loop before you get a timeout problem?? If there is a limitation, then is there a way to work around with this thing?? I'm not sure when you will hit a timeout, but you can send all 1,000 emails in one hit. Give me 5 minutes and I'll post some code. In the meantime, there is a 1,000 email per day limit on PowWeb. That's 1,000 recipients, so you can't send 1 email to 1,001 recipients.

HalfaBee
1-30-04, 01:11 AM
You are supposed to only send 1000 emails per day.

If you do find the loop times out, you will have to split your emails up into batches, or create a php.ini in the dir with an extended timeout value.

PHPGuru
1-30-04, 01:15 AM
Thanks guys,

By the way, I'm not really sending out such mass emails. I was just curious about it. It's good to know things like that if you are programming in PHP :)

Mirzabah
1-30-04, 01:20 AM
// $from = sender
// $recipients = array of recipient email addresses
// $subject = message subject
// $message = message body
$headers = "From: {$from}\\r\\n" ;
$headers .= "Reply-To: {$from}\\r\\n" ;
$recipients = join (", ", $recipients) ;
$headers .= "To: {$recipients}\\r\\n" ;
$result = @mail ("", $subject, $message, $headers) ;

If you wanted to hide the distribution list, do this:

// $from = sender
// $to = visible recipient address
// $recipients = array of recipient email addresses
// $subject = message subject
// $message = message body

$headers = "From: {$from}\\r\\n" ;
$headers .= "To: {$to}\\r\\n" ;
$headers .= "Reply-To: {$from}\\r\\n" ;
$recipients = join (", ", $recipients) ;
$headers .= "Bcc: {$recipients}\\r\\n" ;
$result = @mail ("", $subject, $message, $headers) ;