PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
dubs
Forum Commoner
Posts: 28 Joined: Tue Oct 12, 2004 4:55 pm
Post
by dubs » Thu Dec 02, 2004 11:39 am
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)){
}
}
?>
protokol
Forum Contributor
Posts: 353 Joined: Fri Jun 21, 2002 7:00 pm
Location: Cleveland, OH
Contact:
Post
by protokol » Thu Dec 02, 2004 12:24 pm
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.
kettle_drum
DevNet Resident
Posts: 1150 Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England
Post
by kettle_drum » Thu Dec 02, 2004 3:14 pm
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.
rehfeld
Forum Regular
Posts: 741 Joined: Mon Oct 18, 2004 8:14 pm
Post
by rehfeld » Thu Dec 02, 2004 3:14 pm
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
dubs
Forum Commoner
Posts: 28 Joined: Tue Oct 12, 2004 4:55 pm
Post
by dubs » Fri Dec 03, 2004 11:40 am
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
Joe
Forum Regular
Posts: 939 Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow
Post
by Joe » Fri Dec 03, 2004 12:23 pm
You should think about putting mail() inside the while loop. Also, where are the $mail_to, $mail_subject and $mailbody variables coming from?.
Joe
Forum Regular
Posts: 939 Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow
Post
by Joe » Fri Dec 03, 2004 12:25 pm
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);
}
?>
rehfeld
Forum Regular
Posts: 741 Joined: Mon Oct 18, 2004 8:14 pm
Post
by rehfeld » Fri Dec 03, 2004 12:35 pm
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.....
dubs
Forum Commoner
Posts: 28 Joined: Tue Oct 12, 2004 4:55 pm
Post
by dubs » Sat Dec 04, 2004 5:13 am
Does anyone know how to send direct to the SMTP using sockets
patrikG
DevNet Master
Posts: 4235 Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK
Post
by patrikG » Sat Dec 04, 2004 8:13 am
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