if ($afname && is_uploaded_file($aftmp)) { // it's a file upload, so read it $fp = @fopen($aftmp, 'r'); if ($fp === false) die ('Uploaded file could not be opened.'); $add = fread($fp, filesize ($aftmp)); // just replace existing add value } if ($add == '') $err = 'No addresses specified.'; if (!$err) { $f = openfile($cfg['listfile']); // open list $existing = array(); $succ = array(); $fail = array(); $done = false; $i = 0; while ($item = readitem($f)) $existing[$item['addr']] = true; // read existing addresses if (!$parse) { // we're doing CSV-style parsing $adds = explode($sep, $add); // split into addresses foreach ($adds as $email) { $email = fixemail($email); if ($email == '') continue; // check address is not already in list if (isset($existing[$email])) { $fail[$i]['addr'] = htmlspecialchars($email); $fail[$i]['reason'] = 'Already in list'; } // check each address is correct elseif (!preg_match('#^([a-z0-9\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)?[\w]+[^\".,?! ])$#i', $email)) { $fail[$i]['addr'] = htmlspecialchars($email); $fail[$i]['reason'] = 'Invalid';
} if (!isset($err)) { // create temp file for resume data if ($cfg['enableresume'] && $cfg['savemail']) { if ($_POST['resume']) { $fr = @fopen($cfg['savemailto'].'/tmp_'.substr($_POST['resume'],4), 'wb'); } else { $fr = @fopen($cfg['savemailto'].'/tmp_'.$mfile.'.txt', 'wb'); } if ($fr === false) $err = 'Could not create or open temp file. Check directory permissions.'; } if (!isset($err)) { // WE'RE READY TO SEND!!! $cnt = 0; while ($item = readitem($f)) { // pause if we're on a multiple of the pause interval if ($cfg['pauseinterval'] > 0 && $cnt%(int)$cfg['pauseinterval'] == 0 && $cnt != 0) { sleep((int)$cfg['pausetime']); } // fetch addresses and send if (@mail($item['addr'], $subj, $body, $headers)) $succ++; else $fail++; $cnt++; // update the temp file with resume info if ($cfg['enableresume'] && $cfg['savemail']) { rewind($fr); fwrite($fr, $item['id']."\r\n"); } } }