PHP

HOW TO BULK SEND EMAIL IN PHP

id | int(11) PRIMARY name | varchar(255) INDEXED email | varchar(255) UNIQUE

NEWSLETTER DATABASE TABLE

01

CONNECT TO DATABASE $pdo = new PDO(      "mysql:host=HOST;dbname=NAME;   charset=utf8", USER, PASSWORD );

PHP PART A GET SUBSCRIBERS

02

TOTAL NUMBER OF SUBSCRIBERS $stmt = $pdo->prepare("SELECT COUNT(*) `cnt` FROM `newsletter`"); $stmt->execute(); $all = $stmt->fetch(); $all = $all["cnt"];

PHP PART B GET SUBSCRIBERS

03

$each = 5; subscribers each run $pause = 1; secs pause after each run

for ($i=0; $i<$all; $i+=$each) {   GET BY BATCH   $stmt = $pdo->prepare("SELECT *    FROM `newsletter` LIMIT $i, $each");   $stmt->execute();   $subs = $stmt->fetchAll();

PHP PART C SEND EMAIL

04

  SEND & PAUSE   foreach ($subs as $s) { mail(   $s["email"], "SUBJECT", "TEXT"); }   sleep($pause); }

RUN IN TERMINAL php /PATH/TO/SCRIPT.PHP

OR SCHEDULE - Windows Task Schduler - Linux and Mac Crontab

RUN MASS MAILER

05