isSMTP(); $phpmailer->Host = $smtp_host; $phpmailer->Port = $smtp_port; $phpmailer->SMTPAuth = true; $phpmailer->SMTPSecure = $smtp_secure; $phpmailer->Username = $smtp_user; $phpmailer->Password = $smtp_pass; $phpmailer->From = $smtp_user; $phpmailer->FromName = $sender_name; }); // Send emails in batches $batch_size = intval($_POST[‘batch_size’] ?? 20); $delay = intval($_POST[‘delay’] ?? 1); $results = [‘success’ => [], ‘failed’ => []]; $batches = array_chunk($valid_recipients, $batch_size); $total_batches = count($batches); for ($i = 0; $i < $total_batches; $i++) { $batch = $batches[$i]; foreach ($batch as $recipient) { $headers = [ 'Content-Type: text/html; charset=UTF-8', "From: $sender_name <$sender_email>” ]; $sent = wp_mail($recipient, $subject, $body, $headers); if ($sent) { $results[‘success’][] = $recipient; } else { $results[‘failed’][] = $recipient; } } // Delay between batches (if not last batch) if ($i < $total_batches - 1 && $delay > 0) { sleep($delay); } } echo json_encode([ ‘success’ => true, ‘total’ => count($valid_recipients), ‘sent’ => count($results[‘success’]), ‘failed’ => count($results[‘failed’]), ‘results’ => $results ]); } catch (Exception $e) { echo json_encode([ ‘success’ => false, ‘error’ => $e->getMessage() ]); } exit; } get_header(); ?>

Leave a Reply

Your email address will not be published. Required fields are marked *