needs_upgrade Posted October 26, 2010 Share Posted October 26, 2010 Hello guys. By the end of the day, my client wants the daily report sent to his email account in .xls format. how can i attain this? I know the php mail() function but i dont know how will php create an excel file and email it to my client automatically. Where should i start? Thanks guys! Quote Link to comment https://forums.phpfreaks.com/topic/216857-reports-in-xls-then-email-to-admin/ Share on other sites More sharing options...
harristweed Posted October 26, 2010 Share Posted October 26, 2010 I have found attachments a bit of a nightmare! Why not email a link? $header="column name\t column name\t column name\t column name\t column name\t"; $select="select * from table_name where condition "; $export = mysql_query($select); while($row = mysql_fetch_assoc($export)) { if(empty($row[a]))$row[a]=" "; if(empty($row[b]))$row[b]=" "; if(empty($row[c]))$row[c]=" "; if(empty($d[d]))$row[d]=" "; $line = ''; $line .= "$row[first_name]\t $row[surname]\t $row[email]\t $row[phone]\t $lang[$key]\t"; $data .= trim($line)."\n"; } $data = str_replace("\r","",$data); if ($data == "") { $data = "\n(0) Records Found!\n"; } header("Content-type: application/x-msdownload"); header("Content-Disposition: attachment; filename=$file_name"); header("Pragma: no-cache"); header("Expires: 0"); print "$header\n$data"; Quote Link to comment https://forums.phpfreaks.com/topic/216857-reports-in-xls-then-email-to-admin/#findComment-1126564 Share on other sites More sharing options...
harristweed Posted October 26, 2010 Share Posted October 26, 2010 $line .= "$row[a]\t $row[b]\t $row[c]\t $row[d]\t "; Doh! Sorry bit early for me! Quote Link to comment https://forums.phpfreaks.com/topic/216857-reports-in-xls-then-email-to-admin/#findComment-1126566 Share on other sites More sharing options...
needs_upgrade Posted October 26, 2010 Author Share Posted October 26, 2010 Thanks a lot Harristweed. But what if the admin wants to download the .xls file? Still, thanks for your code. Quote Link to comment https://forums.phpfreaks.com/topic/216857-reports-in-xls-then-email-to-admin/#findComment-1126616 Share on other sites More sharing options...
harristweed Posted October 26, 2010 Share Posted October 26, 2010 Hi To download .xls file just give a link to the php script. Quote Link to comment https://forums.phpfreaks.com/topic/216857-reports-in-xls-then-email-to-admin/#findComment-1126633 Share on other sites More sharing options...
needs_upgrade Posted October 28, 2010 Author Share Posted October 28, 2010 Are the scripts the same? Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/216857-reports-in-xls-then-email-to-admin/#findComment-1127332 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.