Send message to the emails included in the file

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

function send_message_to_emails_included_in_file($file,$subject,$message,$headers="", $parameters=""){
      $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){
      return true;
      return false;
$file = "file.txt"; // the path of the file
$subject = "Hello"; // email subject
$message = "This is a test message."; // email massage
$headers = "From:"; // email headers

If the file is not found the function return false.

  • Share/Bookmark
1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 5.00 out of 5)
Loading ... Loading ...

Leave a Reply