Page 1 of 1

Sending Large Amounts of Emails

Posted: Thu Dec 02, 2004 11:39 am
by dubs
I'm using the following code to bulk email my members, however, there's just too many emails in my database...and it kills my server.

Is there any why of getting my script to process 50 emails at a time and then refresh or load the page again and process the next 50 unitil complete.

Code: Select all

<?php
$sqlemail = "SELECT email.emailaddress,email.emailid FROM email WHERE ((email.emailid BETWEEN 1001 and 1500))";
$rsemail = mysql_query($sqlemail,$link);

$headers = "From:Speed Detectors UK<$mail_from>\r\n";
$headers .= "Content-type: text/html\r\n"; 
$headers .="reply-to:info@speed-detectors.co.uk";
set_time_limit(1000);
while ( $row = mysql_fetch_array($rsemail)) { 	
	if (mail($row["emailaddress"], $mail_subject, $mail_body, $headers)){
	}
}

?>
8O

Posted: Thu Dec 02, 2004 12:24 pm
by protokol
Why not just make the To: field yourself and then make the BCC: field a list of the email addresses. This way you send out one email and let the mail servers distribute to the correct people.

Posted: Thu Dec 02, 2004 3:14 pm
by kettle_drum
I always create an email stack where i add emails that i wish to send, and then send all the emails in the stack when i wish or when the server is not under load. Once you create the stack in a database table, just select them and limit the query to x number of rows. Then send these emails, remove them from the stack, and repeat until its empty.

Posted: Thu Dec 02, 2004 3:14 pm
by rehfeld
you can also open a socket and send emails in bulk that way

look on zend.com in the code gallery, i saw a script or 2 there that did this

Posted: Fri Dec 03, 2004 11:40 am
by dubs
protokol wrote:Why not just make the To: field yourself and then make the BCC: field a list of the email addresses. This way you send out one email and let the mail servers distribute to the correct people.
I've tried to do this buy building a string of emails with ; as a separator but it errors on the mail function.

Code: Select all

<?php
$bccemail = "";
while ( $row = mysql_fetch_array($rsemail)) { 
	$bccemail = $bccemail . $row["emailaddress"] . ';';
}

$headers = "From:Speed Detectors UK<$mail_from>\r\n";
$headers .= "Content-type: text/html\r\n"; 
$headers .= "nBcc: $bccemail \r\n";
$headers .="reply-to:info@speed-detectors.co.uk";

mail($mail_to, $mail_subject, $mail_body, $headers);

?>
What am i doing wrong

Posted: Fri Dec 03, 2004 12:23 pm
by Joe
You should think about putting mail() inside the while loop. Also, where are the $mail_to, $mail_subject and $mailbody variables coming from?.

Posted: Fri Dec 03, 2004 12:25 pm
by Joe
Try something like:

Code: Select all

<?php
$headers = "From:Speed Detectors UK<$mail_from>\r\n";
$headers .= "Content-type: text/html\r\n";
$headers .= "nBcc: $bccemail \r\n";
$headers .="reply-to:info@speed-detectors.co.uk";
$mail_subject = "testing";
$mail_body = "Message here...";

while (true) {     
 $row = mysql_fetch_assoc($rsemail);
 if ($row == false) break;
 $mail_to = $row['emailaddress'];
 mail($mail_to, $mail_subject, $mail_body, $headers);
}
?>

Posted: Fri Dec 03, 2004 12:35 pm
by rehfeld
dont you use a comma, not semicolon to seperate the emails?


and what is nBcc: ? looks like a typo

still, opening a socket is the most efficient way to send bulk emails.....

Posted: Sat Dec 04, 2004 5:13 am
by dubs
Does anyone know how to send direct to the SMTP using sockets

Posted: Sat Dec 04, 2004 8:13 am
by patrikG
dubs wrote:Does anyone know how to send direct to the SMTP using sockets
rehfeld wrote:you can also open a socket and send emails in bulk that way

look on zend.com in the code gallery, i saw a script or 2 there that did this