filter_var($r,FILTER_VALIDATE_EMAIL)); if (empty($list)) $errors[]="No valid recipient addresses found"; if ($errors) json_response(['ok'=>false,'errors'=>$errors],400); // Always HTML $headers = [ "From: {$sender_name} <{$sender_email}>", "Reply-To: {$sender_email}", "MIME-Version: 1.0", "Content-Type: text/html; charset=utf-8" ]; $headers_str = implode("\r\n",$headers); $sent_to=[]; foreach($list as $to){ if(@mail($to,$subject,$message,$headers_str)){ $sent_to[]=$to; } } if($sent_to){ json_response(['ok'=>true,'sent'=>$sent_to,'count'=>count($sent_to)]); } else { json_response(['ok'=>false,'errors'=>['mail() failed for all recipients']],500); } } ?> Dynamic PHP Mailer (HTML-only)

Kosko Dynamic Mailer (KDM)