Functional HTML form poops data to this thing, which then supposedly creates a file and then either sits on it or shoots it to someone else.
Except that it hates me and won’t do diddly squat. After hours of dicking around I’ve grabbed all the bugs I can find, but now my weak and burn-y eyes are failing me.
As far as I can tell, I’m screwing up with creating the file, and am pretty much unable to think further. Since I’ve been making functionally random changes to it at this point, I figured it was time to call for halp from people who aren’t crazy. Halp!
Yes there is a mail exchanger on the box, I use it for another script that IS working. Yes the HTML form is posting fine. Yes it calls up the right script (I echo’d swear words at myself a few times to check). No none of the variables are misspelled (although those aren’t technically the HTML variables I’m using, call me paranoid. Yes it has correct permissions.
If someone figures out what blindingly obvious thing I have done wrong, I will send you something I didn’t cook so that you won’t die. Possibly it will be a PM with a picture of a spider.
<!DOCTYPE html>
<html>
<title></title>
<body>
<?php
function handleMail($path, $fileName, $quarter){
$from_mail = 'redact';
$from_name = 'redact';
$replyto = $from_mail;
$mailto = 'redact';
$message = 'nerp';
$subject = $quarter. 'derg';
$file = $path.$filename;
$file_size = filesize($file);
$handle = fopen($file, "r");
$content = fread($handle, $file_size);
fclose($handle);
$content = chunk_split(base64_encode($content));
$uid = md5(uniqid(time()));
$name = basename($file);
$header = "From: ".$from_name." <".$from_mail.">
";
$header .= "Reply-To: ".$replyto."
";
$header .= "BCC: " . $from_mail;
$header .= "MIME-Version: 1.0
";
$header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"
";
$header .= "This is a multi-part message in MIME format.
";
$header .= "--".$uid."
";
$header .= "Content-type:text/plain; charset=iso-8859-1
";
$header .= "Content-Transfer-Encoding: 7bit
";
$header .= $message."
";
$header .= "--".$uid."
";
$header .= "Content-Type: application/octet-stream; name=\"".$filename."\"
"; // use different content types here
$header .= "Content-Transfer-Encoding: base64
";
$header .= "Content-Disposition: attachment; filename=\"".$filename."\"
";
$header .= $content."
";
$header .= "--".$uid."--";
if (mail($mailto, $subject, "", $header)) {
echo "mail send ... OK"; // or use booleans here
} else {
echo "mail send ... ERROR!";
}
}
//main
$toFile[0] = $_REQUEST('a');
$toFile[1] = $_REQUEST('b');
$toFile[2] = $_REQUEST('c');
$toFile[3] = $_REQUEST('d');
$toFile[4] = $_REQUEST('e');
$toFile[5] = $_REQUEST('f');
$sendNow = $_REQUEST('g');
$curDate = getdate();
$day = $curDate[mday];
$month = $curDate[mon];
$year = $curDate[year];
$quarter = $year;
if($isnull($toFile[3]) == true) {
$toFile[3] = $day . "." . $month . "." . $year;
}
for($i = 0; $i < 6; $i++) {
if ($i== 0){
$fileContent = PHP_EOL . $toFile[i] . ',';
}
$fileContent .= $toFile[i] . ', ';
}
$fileName = $month . 'm' . $year . 'y' . '.txt';
$path = './'.$fileName;
$file=fopen($fileName,'a') or exit("Unable to open file!");
file_put_contents($file, $fileContent, FILE_APPEND);
if ($day > 29) {
switch ($month) {
case 3:
$quarter .= ' Q1';
handleMail($path, $fileName, $quarter);
break;
case 6:
$quarter .= ' Q2';
handleMail($path, $fileName, $quarter);
break;
case 9:
$quarter .= ' Q3';
handleMail($path, $fileName, $quarter);
break;
case 12:
$quarter .= ' Q4';
handleMail($path, $fileName, $quarter);
break;
}
}
//debug
if ($sendNow ==1){
$quarter = 'DEBUG';
handleMail($path, $fileName, $quarter);
echo "sent DEBUG message";
}
else if ($day > 29) {
echo "message sent";
}
else {
echo "info saved";
}
?>
</body>
</html>