1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
|
$query = "select email from dbtable where sub_status = 1 LIMIT 1000";
$req = $db->prepare($query);
$req->execute() or die(print_r($req->errorInfo()));
$rows = $req->fetchAll();
$emails = array();
$nbr = 100;
$i = 0;
foreach ($rows as $row) {
$emails[]=$row['email'];
}
$count = file_get_contents("count.txt");
for($i=$count;$i<count($emails);$i++){
$to = $emails[$i];
$subject = 'Titre';
if ($i % $nbr == 0){
sleep(10);
}
$message = file_get_contents("newsletter.html");
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: Name <info@domain.com>' . "\r\n";
if(mail($to, $subject, $message, $headers)) {
$file = fopen("sentlist.txt","a+");
fwrite($file, $to.",\r\n");
fclose($file);
} else {
$file = fopen("notsentlist.txt","a+");
fwrite($file, $to.",\r\n");
fclose($file);
}
if(($i-$count)>=1000) {
$filec = fopen("count.txt",'w');
fwrite($filec, $i);
fclose($filec);
break;
}
$++;
}
$filec = fopen("count.txt",'w');
fwrite($filec, $i);
fclose($filec); |
Partager