This function is used for sending message to the emails included in the file text.

<?php
function send_message_to_emails_included_in_file($file,$subject,$message,$headers="", $parameters=""){
   if(file_exists($file)){
      $content = file_get_contents($file, true);
      preg_match_all('/(\w+\.)*\w+@(\w+\.)*\w+(\w+\-\w+)*\.\w+/', $content, $emails, PREG_PATTERN_ORDER);
 
      $emails = $emails[0];
      $emails = array_unique($emails);
 
      foreach($emails as $email){
         mail($email,$subject,$message,$headers,$parameters);
      }
      return true;
   }else{
      return false;
   }
}
 
$file = "file.txt"; // the path of the file
$subject = "Hello"; // email subject
$message = "This is a test message."; // email massage
$headers = "From: rubensargsyan.com"; // email headers
 
send_message_to_emails_included_in_file($file,$subject,$message,$headers);
?>

If the file is not found the function return false.

Share

Leave a Reply

Info