A cron job is a "job" that is run by the cron daemon. It is basically a daemon that will execute a script at a set time, be it every minute, every other 5 minutes, or every month. You create a script that will scan your DB and email the users. Basically, eveytime you refresh that page, it should scan the DB and send emails. So all the cron has to do is launch the script, which should reside outside of the web root.
Here is a link: http://www.phpfreaks.com/tutorials/28/0.php
As far as the CSV goes, I don't recall one being mentioned.
What you would do is create your form, and have a group of checkboxes in an array. Once the data is posted, you would [man]implode[/man] the array seperating them by comma. So your checkbox array would look like: doc1,doc3,doc4
You would then insert that into a column, along with the users email addresses in another.
TABLE: doc_wanters
+--------------------------------
+email | docs
+--------------------------------
jeff@unknown.com | 1,2,5
travis@me.com | 3,4
tim@google.com | 1,2,4,5
So...
In your cron script (which is just another PHP script by the way), would access the doc_wanters table, and pull out everything and go through them one by one.
... this is getting kinda hard to explain ... here is a snippet (untested and unsecure)
<?php
//lets say hypothetically that the docs are text files
//stored on the server ... so we give them a path
$doc1 = 'home/user/docs/doc1.txt';
$doc2 = 'home/user/docs/doc2.txt';
$doc3 = 'home/user/docs/doc3.txt';
$doc4 = 'home/user/docs/doc4.txt';
$doc5 = 'home/user/docs/doc5.txt';
//connect to the DB
//setup the main query
$sql = @mysql_query("SELECT * FROM doc_wanters");
//loop through results
while($fetch = @mysql_fetch_array($sql)){
//get info
$email = $fetch['email'];
$getdocs = $fetch['docs'];
//notice that $getdocs is a string, we need to turn it into an array
$docs = explode(",", $getdocs);
//now $docs = array();
//so now we can pull the text from the docs and
//include them in our email
//loop through wanted docs
foreach($docs as $doc){
//create a switch to figure out which doc they want
switch($doc){
case 'doc1':
$wanted = $doc1;
break;
case 'doc2':
$wanted = $doc2;
break;
case 'doc3':
$wanted = $doc3;
break;
case 'doc4':
$wanted = $doc4;
break;
case 'doc5':
$wanted = $doc5;
break;
default:
$wanted = $doc1;
}//end switch
//now we know which doc to send for this pass of the user
//open the file desired and get the text from it
$handle = fopen($wanted, "r");
$text = fread($handle, filesize($wanted));
//there is more to do, but that's up to you
//for now, it is safe to email the user the info though
if(mail($email, "Documents from web site.", $text, "FROM: Your Name <you@web.com>\r\n"))
echo 'Email sent to '.$email.'<br>';
else
echo 'Could not send email to '.$email.'<br>';
}//end foreach loop
} //end while and end of script
echo 'Script finished.';
//since the cron daemon will be the only one running this script
//the echo statement above is for debuggin only ... cause the computer cant read
?>
Please remember that this is untested and is only for demo and educational purposes.
It is also the cron script, so you will need to create your form and all that jazz.
Helpful hint, on your checkbox name, be sure to define it as an array.
i.e.
<input type="checkbox" group="docs" name="doc[]">
The [] tells the computer gods that the checkbox should be passed as an array.
Hope that helps some...
#########EDIT##########
Typo ... it is frickin 8:38 AM ... leave me alone 😉