The email attachment for the csv file keeps ringing up 0 bytes in the filesize. I can get it to download via browser, but for some reason it won't send the file to email.
It sends the attachment, but for some reason it turns out to be a blank .csv file. What are my problems in the code?
<?
// generate table.csv file
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=table.csv");
header("Content-Transfer-Encoding: binary");
$query = "SELECT * FROM datainfo";
$result = mysql_query($query) or die(mysql_error());
$numOfRows = mysql_num_rows($result);
for ($i = 0; $i < $numOfRows; $i++){
$id = mysql_result ($result, $i, ID);
$ageverification = mysql_result ($result, $i, ageverification);
$creditchecking = mysql_result ($result, $i, creditchecking);
$First_Name = mysql_result ($result, $i, First_Name);
$Last_Name = mysql_result ($result, $i, Last_Name);
$email = mysql_result ($result, $i, email);
$DayPhone = mysql_result ($result, $i, DayPhone);
$EvePhone = mysql_result ($result, $i, EvePhone);
$Address = mysql_result ($result, $i, Address);
$City = mysql_result ($result, $i, City);
$State = mysql_result ($result, $i, State);
$Zip = mysql_result ($result, $i, Zip);
print "$id\",\"$ageverification\",\"$creditchecking\",\"$First_Name\",\"$Last_Name\",\"$email\",\"$DayPhone\",\"$EvePhone\",
\"$Address\",\"$City\",\"$State\",\"$Zip\"\"\n";
}
$file = "table.csv";
$file_source = "/home/browngai/public_html/testing/table.csv";
$adminemail = "persona@animeorganizations.com, [email]shinmeiryu_san@yahoo.com[/email]";
$subject = 'Weekly csv imported file for today: '.date("l, F jS Y").'';
$message = "
To the admin,
Here is your csv imported as an e-mail attachment.";
$message.= "\n \n ================= \n \n";
// set up the attachment
$headers .= "From: Properhosting Webmaster<webmaster@properhosting.com>\n
X-Mailer: PHP/" . phpversion();
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: multipart/mixed; boundary=\"CCM-12345\"\r\n\r\n";
$headers .= "This is a MIME encoded message\r\n\r\n";
$headers .= "--CCM-12345\r\n";
$headers .= "Content-Type: text/plain; charset=\"us-ascii\"\r\n";
$headers .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
$headers .= "Please find attached file\r\n\r\n";
$headers .= "$message\r\n\r\n";
$headers .= "--CCM-12345\r\n";
$headers .= "Content-Type: application/octet-stream; name=\"$file\"\r\n";
$headers .= "Content-Transfer-Encoding: base64\r\n";
$headers .= "Content-Disposition: attachment; filename=\"$file\"\r\n\r\n";
set_magic_quotes_runtime(0);
$fp = fopen($file_source, "rb");
$fstr = fread($fp, filesize($file_source));
$headers .= chunk_split(base64_encode($fstr),72);
fclose($fp);
set_magic_quotes_runtime(get_magic_quotes_gpc());
$headers .= "\r\n";
$headers .= "--CCM-12345--\r\n\r\n\r\n";
echo "<pre>$headers</pre>";
// send the email out to administrators
mail($adminemail, $subject, $message, $headers);
?>