データベースの方法は、確かに最良の方法です。テキストファイルのアプローチを使用する場合は、次のようなものをお勧めします。
ファイルへのデータの挿入
$email = "the email";
$firstName = "the first name";
$lastName = "the last name";
$new_line = "$email|$firstName|$lastName\n"; // | could be other character
$file = fopen("subscribers.txt", "a");
fputs($file, $new_line);
fclose($file);
データの読み取りと解析
$subscribers = array();
$handle = @fopen("subscribers.txt", "r");
if ($handle) {
while (!feof($handle)) {
$line = fgets($handle, 4096);
//parsing the line
$ar = explode('|', $line);
//$ar[0] holds the email
if(key_exists(0, $ar)){
$email = $ar[0];
}else{
$email= '';
}
//$ar[1] holds the first name
if(key_exists(1, $ar)){
$firstName = $ar[1];
}else{
$firstName = '';
}
//$ar[2] holds the last name
if(key_exists(2, $ar)){
$lastName = $ar[2];
}else{
$lastName = '';
}
$temp = array(
'email' => $email,
'firstName' => $firstName,
'lastName' => $lastName
);
$subscribers[] = $temp;
//
}
fclose($handle);
}
サブスクライバーをループし、関数を使用してメールを送信するため
foreach($subscribers as $subscriber){
//the email
$subscriber['email'];
//the firstname
$subscriber['firstName'];
//the lastname
$subscriber['lastName'];
}