tetuanrp Posted January 20, 2008 Share Posted January 20, 2008 Got two scripts which I'm trying to combine. One which when run, takes my mysql db and dumps it into an excel sheet, then prompts the browser to download. The other is your basic mail() script. I would like to combine these, so when I run the first script, instead of prompting the browser it adds it as an attachment to an email. Is that tough? I feel the hardest part is creating the file, not attaching it. Here's my code: <?php include 'config.php'; include 'opendb.php'; $query = "SELECT * FROM orders"; $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>"; $fileName = date('m-d-Y').'.xls'; header("Content-type: application/vnd.ms-excel"); header("Content-Disposition: attachment; filename=$fileName"); echo $tsv; //echo $html; include 'closedb.php'; //MAIL SCRIPT $to = 'me@mysite.com'; $subject = 'Excel Sheet'; $message = 'My Sheet'; $additionalHeaders = "From: me@mysite.com\n"; $OK = mail($to, $subject, $message, $additionalHeaders); ?> I take it $tsv is the file?? So how can I do a simple mail and add it as an attachment? Thanks in advance Ryan Quote Link to comment https://forums.phpfreaks.com/topic/86944-mail-excel-sheet-attachment/ Share on other sites More sharing options...
PHP Monkeh Posted January 20, 2008 Share Posted January 20, 2008 <?php header("Content-type: application/vnd.ms-excel"); header("Content-Disposition: attachment; filename=$fileName"); ?> These are the two lines which are prompting the download, so remove those to start off with. From that you can see that $fileName is the file, so if you find an e-mail script which will use file attachments, replacing $fileName in to it should do what you want (I hope). Quote Link to comment https://forums.phpfreaks.com/topic/86944-mail-excel-sheet-attachment/#findComment-444541 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.