特定の文字列(5126など)を含むファイルをディレクトリで検索するスクリプトがあります。次に、ファイル名にその文字列が含まれている各ファイルの名前を変更し、ファイル名の前に別の文字列を付けます(例:'coursefile5126)。このビットは正常に機能します。文字列の名前が変更された後、これがファイルである人に電子メールを送信したいと思います。現時点では、私のスクリプトは、配列に最後に返された人にのみ、すべてのファイルへのリンクを電子メールで送信します。以下の例とコードを参照してください。
ファイル名の例:
- Test_47-20120908-154525-5126.zip
- Test_48-20120908-155253-5126.zip
- Test_49-20120908-160226-5125.zip
配列の例:
- email1 @ email.com、51、26
- email2 @ email.com、51、25
ご覧のとおり、test_47とtest_48のリンクはemail1@email.comに送信し、test_49はemail2@email.comに送信する必要がありますが、現時点では、すべての電子メールは配列の最後の電子メール(email2 @ email)に送信されます。この例ではcom)
誰かが私がこれでどこが間違っているのかについての手がかりを教えてもらえますか?
ありがとう。
$dh = scandir("courses/");
...some SQL query here that returns an array
$i=0;
while ($data= mysql_fetch_array($query)) {
$j=1;
//this is the array returned by the SQL query
echo $data["email"]."-".$data["id_cart"]."-".$data["id_product"]."<br/>";
while ($j<sizeof($dh)) { //Ensures there are courses to look for
// this looks for courses that have not yet been renamed and prefixes them with the string 'coursefile' if necessary
if(end(explode("-",$dh[$j]))==$data["id_product"].$data["id_cart"].".zip" && reset(explode("-",$dh[$j])) != 'coursefile')
{
rename('courses/'.$dh[$j],'courses/'.'coursefile-'.$dh[$j]);
//sends email ---- this is where my problem lies I think
$to = $data["email"];
$subject = 'Your link to download your course';
$message = 'Link: http://www.website.com/courses/'.'coursefile-'.$dh[$j];
$headers = 'From: contact@website.com' . "\r\n" .
'Reply-To: contact@website.com' . "\r\n";
mail($to, $subject, $message, $headers);
}
$j++;
}
}