Sho Gum Lew
Sho Gum Lew

Reputation: 339

How to send the download link of CSV file in email

I'm generating a weekly CSV file using a PHP script, then I need to send the address of it (basically the destination where it was generated) via an email in order to download it, all this happens using a CRON so can anybody tell me how to do this? (not the CRON part but just how to add the correct download link). For example:

var/www/Reports/weeklyReport/Weekly_Report_From_20-01-2015_to_27-01-2015.csv

But the problem is currently I have no way to get the latest report automatically in it

CSV generated code:

$exportBaseDir = 'var/www/Reports';
$fileD = "Weekly_Report_From_".date('d-m-Y', strtotime('-1 week'))."_to_".date('d-m-Y').".csv";
$basePath = "$exportBaseDir/weeklyReport/$fileD";

$fp = fopen($basePath, 'w');

fputcsv($fp, $header, ',');
foreach ($tables as $fields) {
    fputcsv($fp, $fields,',');
} 

This happens at the end of every week, the file names are like this:

Weekly_Report_From_20-01-2015_to_27-01-2015.csv
Weekly_Report_From_27-01-2015_to_06-02-2015.csv 
Weekly_Report_From_06-02-2015_to_13-02-2015.csv etc etc

Email body:

$mail->Subject = "Testing Weekly report with localhost";
$mail->Body = "Hi,<br /><br />This system is working perfectly <LINK>.";

I need to put the correct file (the latest one) in the email body, can anybody help me on this?

Upvotes: 1

Views: 594

Answers (1)

Tariq hussain
Tariq hussain

Reputation: 614

i think you should use mail function when u uploading a csv file it will automatically put the correct file in url ..

if(fputcsv($fp, $header, ',')){

$mail->Subject = "Testing Weekly report with localhost";
$mail->Body = "Hi,<br /><br />This system is working perfectly <a href=".$basePath.">file</a>.";

}

Upvotes: 1

Related Questions