What would be the best way to mass email? Using Mail()? If so is there a way to ease the lag on the server?
Printable View
What would be the best way to mass email? Using Mail()? If so is there a way to ease the lag on the server?
Any insight?
Why are you trying to mass email?
for a newsletter that visitors have signed up for.
My suggestion is to send them 100 mail address apart that way the script doesn't time out.
Like send 100 emails, refresh the page then do the next 100.
how would you do this programmicaly? so the end user wouldn't have to do anything.
I recently made a PHP script that opened my fonts folder and made an image of each font writing the same sample text and then saving it to a predetermined directory, and also logged its ID, filename and date into a MySQL database. Because of the amount of time it would take to create 2000+ images, I made it run 300 at a time. I didn't make it fully-automated, but that's not to say that it cannot be done. This is a sample from the script I was talking about, you'll have to try to adapt it to what you're doing.. I've added some comments to try to explain it a little.
I grabbed all the useful stuff and put it together and made sure it worked (and also created a sample array, and changed the increment from 300 to 40 because, frankly, I didn't want to make an array with over 300 elements just to show you it worked!) This code will run AS-IS, and to give you an idea of it and to show you it working, I uploaded it here.PHP Code:<?
//check if the user has "started" yet
if(isset($_GET['start']) && is_numeric($_GET['start']) && $_GET['start'] >= 0){
$fonts = array("this is just", "some samples", "because my array", "was populated with", "a readdir()",
"this is just", "some samples", "because my array", "was populated with", "a readdir()",
"this is just", "some samples", "because my array", "was populated with", "a readdir()",
"this is just", "some samples", "because my array", "was populated with", "a readdir()",
"this is just", "some samples", "because my array", "was populated with", "a readdir()",
"this is just", "some samples", "because my array", "was populated with", "a readdir()",
"this is just", "some samples", "because my array", "was populated with", "a readdir()",
"this is just", "some samples", "because my array", "was populated with", "a readdir()",
"this is just", "some samples", "because my array", "was populated with", "a readdir()");
$start = $_GET['start'];
$increment = 20; //number of things to process per step
$max = $increment;
if(($start + $max) > count($fonts)) $max = count($fonts);
$addmax = $start;
if($max == count($fonts)) $addmax = 0;
for($i = $start; $i < ($addmax+$max); $i++){
//send your emails, you will have to have addresses in an array so that you can
//call them using $arrayname[$i] (the array i am using in this case is $fonts)
echo $i . " done - ";
}
?>
<a name="b"></a>done processing fonts <?=$start + 1;?> to <?=$addmax + $max;?>.
<?
//make a link for the next step
if(($start + $increment) < count($fonts)){
$endproc = $start + ($increment * 2);
if($endproc > count($fonts)) $endproc = count($fonts);
?>
<a href="?start=<?=$start + $increment;?>#b">>> process fonts <?=$start + $increment + 1;?> to <?=$endproc;?></a>
<? }else{ ?>
<a name="b"><b></a>done processing <?=count($fonts);?> fonts</b>
<?
}
}else{ //user has NOT started yet, so just give them a link/make a form to start
echo '<a href="?start=0">start now</a>';
}
?>
Now, you can either use this to create 300 different mail() calls every loop, or do a mail() only after the for() is finished and use the for() to populate a variable with 300 different emails, seperating each email with a semi-colon to represent multiple people (i'm fairly sure you can do this, although i'm not positive because i haven't used mail() for a while, and never tried to do it for multiple people)
Now, to make it automated all you really need to do is eliminate any output that it's giving throughout the script (like the echoing in the for() loop) and add a header() that has a Location: url, the URL being the URL in the "next" link. Without testing it, I would say that should work fine. An alternative if it doesn't, is to use a <meta> tag after finished processing that refreshes to the next page, or even a JavaScript that redirects, depending on your browser (some Gecko browsers, to my knowledge, don't use the meta redirect tags correctly, but the JavaScript call is a hack to redirect them)
Oh, and a shameless plug, if anyone wanted to see my font database, you can view it here! Overall, it's useless, but I thought it would be a neat thing to do.
Hmmm, this sounds suspicious because no one referres to a newsletter as being mass mailing. Sounds kinda malicious, can you point to your site that has proof on it of some sort, cause mass mailing is actually against the law, unless of course for a newsletter.
actually, I refer to it as mass mailing, and I'm not a spammer. Saying it's a newsletter is the common person's outlook on it, mass mailing is the way a programmer might look at it.
We had this very problem about two months back. Search this forum for mail and timeout.