Email PHP output
Posted: Fri Feb 15, 2008 8:40 am
I have a script that converts a mysql table to xls for users who would like to use it on our site.
Here is the code
Lots of people call wanting this emailed and faxed (just need to save as txt file to a directory and my fax server will take it from there) to them so I am working on a couple of scripts that would allow me to submit a form from our office that would run the script and email as an attachment (or save as txt). I have been playing with it but so far I have nothing that will work.
Does anyone know what direction I should go?
Here is the code
Code: Select all
<?php
include 'availconfig.php';
include 'availopendb.php';
$fileName = 'North_Carolina_Farms_Inc_Availabiity.xls';
header("Content-type: application/vnd.ms-excel");
header("Content-Disposition: attachment; filename=$fileName");
$query = "SELECT * FROM avail";
$result = mysql_query($query) or die('Error, query failed');
$tsv = array();
$html = array();
while($row = mysql_fetch_array($result, MYSQL_NUM))
{
$tsv[] = implode("\t", $row);
$html[] = "<tr><td>" .implode("</td><td>", $row) . "</td></tr>";
}
$tsv = implode("\r\n", $tsv);
$html = "<table>" . implode("\r\n", $html) . "</table>";
echo $tsv;
//echo $html;
include 'availclosedb.php';
?>
Does anyone know what direction I should go?