Q:

Cron Job seemingly not registering arguments for PHP script, but the script is configured to except them

I'm scheduling dynamic cron jobs based on the contents of an Excel file with php, and passing those values to a script in argv.  My code is as follows:
$data = new SpreadSheet_Excel_Reader("sample-data.xls", false);

$surveyToken = "Token";
$email = rawurlencode($data->val(2, "B"));
$dateCompleted = rawurlencode($data->val(2, "C"));
$followUpOne = rawurlencode($data->val(2, "E"));
$followUpTwo = rawurlencode($data->val(2, "F"));
$programName = rawurlencode($data->val(2, "G"));
$subject = rawurlencode($data->val(2, "H"));
$firstName = rawurlencode($data->val(2, "I"));
$lastName = rawurlencode($data->val(2, "J"));
$learningGoal = rawurlencode($data->val(2, "K"));
$importanceScore = rawurlencode($data->val(2, "L"));
$confidenceScore = rawurlencode($data->val(2, "M"));
$strategies = rawurlencode($data->val(2, "N"));
$timeLine = rawurlencode($data->val(2, "O"));
$measures = rawurlencode($data->val(2, "P"));
$resources = rawurlencode($data->val(2, "Q"));

$output = shell_exec("crontab -l");
file_put_contents("crontab.txt", $output . "39 * * * * /usr/local/php53/bin/php mail.php $surveyToken $email $dateCompleted $followUpOne $followUpTwo $programName $subject $firstName $lastName $learningGoal $importanceScore $confidenceScore $strategies $timeLine $measures $resources" . PHP_EOL);
exec("crontab crontab.txt");

I'm using a raw URL decode in the mail.php script and sending that email by getting the variables from argv.  
I have tested this script by simply executing it on the command line with the outputted "url" and its arguments, not scheduling a cron job for it.
When I execute it like that, it works fine.  When I run the code above, the cron job works well and the php file still emails me, but all the variables are empty from argv.

A:

When you send arguments to the command line / shell_exec, you should not use rawurlencode() as it is not a url.
Instead, you should use escapeshellarg(); this escapes the variables correctly to be used in shell_exec.
Apart from that I would try to avoid dynamic scheduling like this; I would just run a cron-job every hour that reads the Excel file and includes the mail file. You could use a database of something similar if you want to generate a job queue.

