Log in

View Full Version : How to send batch email in php?



tryangle_com
08-29-2011, 04:55 AM
Hi there,

am currently writing a mass mail web application in php. The thing is that the software should be able to send e-mail in batches and pause interval between.

I wrote this little script to send in batch:



if($totalemails <= 5000) {
$batch = 400;
$interval = 60;
} elseif($totalemails <= 15000) {
$batch = 500;
$interval = 90;
} elseif($totalemails <= 30000) {
$batch = 300;
$interval = 120;
} elseif($totalemails <= 50000) {
$batch = 200;
$interval = 120;
} else {
$batch = 100;
$interval = 180;
}


But the above script is the wrong way because if the user has 400 emails. The system will send all the 400 recipient at one time hence no pause interval.

Can you please help me the find a solution to this? The system should calculate how many batch either $totalemails = 400 or $totalemails = 40000 for example.

The interval can be 60 seconds in every cases.

Waiting for you help.
Thanks

djr33
08-29-2011, 06:00 AM
That's just assigning values to variables. You could use a switch statement instead if you'd like, but it's somewhat irrelevant. The code that will actually determine the action must be in the sending loop.

You can use the sleep() function to pause for a certain number of seconds.


But be careful sending "mass emails" with PHP. There are probably limits in place by your server, or potentially the ISP, and you may be marked as spam. There also may be legal limits depending on the specifics of your situation.


Note that there are some available software products (some free even) for newsletters and so forth, including lots of messages. This might be easier if you're just looking for a solution rather than intending to build it using your own code specifically.