0

I have a problem on sending message to email list(text file).

Code:

<?php
$to="emails.txt";
$subject="Hey";
$txt="Hello...";
mail($to,$subject,$txt);
?>

i do not have any syntax errors.... the msg is not sent to the emails list , that is the proplem here

Please advice and Thanks

Amir
  • 65
  • 6
  • if you have some txt file where every email address in new line, you can make this: `$file = fopen("file.txt", "r"); $subject="Hey"; $txt="Hello..."; while(!feof($file)){ $to = fgets($file); mail($to,$subject,$txt); } fclose($file);` – Samuel Loog Sep 22 '16 at 11:45
  • @Samuel Loog , Tnx alot worked [: – Amir Sep 22 '16 at 21:06

2 Answers2

0

if you have some txt file where every email address in new line, you can make this:

$file = fopen("file.txt", "r");
$subject="Hey";
$txt="Hello...";
while(!feof($file)){
    $to = fgets($file);
    mail($to,$subject,$txt);
}
fclose($file);
Samuel Loog
  • 272
  • 1
  • 2
  • 18
0

$to variable in your code contains the text only from the file name, but not the details of it. To be successful, you need to get data from a file and run them by sending a letter to each.

function file() reads a file into an array, and FILE_IGNORE_NEW_LINES key removes the line break charset value of each row. Thus it is possible to obtain an array of emails.

$arrayTo = file("file.txt", FILE_IGNORE_NEW_LINES);
$subject="Hey";
$txt="Hello...";
foreach($arrayTo as $to){
    mail($to,$subject,$txt);
}
Samuel Loog
  • 272
  • 1
  • 2
  • 18