-1

I am working on one assignment. I had to write code for sending the report in email. When I open HTML page and click on the button then it sends in email.

BUT suppose I have 10 reports, and I want that when I click on send button it should send in email. Because I have used

$html=file_get_contents("html_report.html");

in PHP code. It works for only html_report.html but I want it to work for rest 10 files.

For example : I have 1.html,2.html...10.html,I want to that whenever I open any HTML file and click on the button then it should send. So what should I write in

$html=file_get_contents("WHAT SHOULD I WRITE HERE");

so that it will work for 10 files.

any help will be appreciated.

Not a bug
  • 4,286
  • 2
  • 40
  • 80
BlackFrog
  • 29
  • 6

6 Answers6

1

add this code on the page who's url you want to use:

<?php $_SESSION['url'] = $_SERVER['REQUEST_URI']; ?>

and then use this url from session

shruti
  • 780
  • 9
  • 25
1

you can use the array to loop all those html file.LIKE:

$reports = array("1.html", "2.html", "3.html", ...... "10.html");

then loop the $reports.

foreach ($reports as $report) {
   $html = file_get_contents("WHAT SHOULD I WRITE HERE");
   ........
}
chen
  • 407
  • 2
  • 9
0

use:

$_SERVER['REQUEST_URI'];

to get the current url.

ReNiSh AR
  • 2,782
  • 2
  • 30
  • 42
0

You will have to get HTML in loop and then send email.

<?php
$arrTemplates = array('html_report1.html','html_report2.html','html_report3.html','html_report4.html','html_report10.html');
foreach($arrTemplates as $htmlFileName) {
    $html=file_get_contents($htmlFileName);
    // CODE FOR SEND EMAIL
}
?>

Hope this will work for you.

Vinay
  • 325
  • 1
  • 8
0

With For Loop

<?php
for ($x=1; $x<=10; $x++)
{
$html=file_get_contents("html_report".$x.".html");
// Send email
}
?>   

With arrays

<?php
$reports=array("page1.html","page2.html","page3.html");
$arrlength=count($reports);
for($x=0;$x<$arrlength;$x++)
{
$html=file_get_contents($reports[$x]);
// send Email
}
?>
Shn
  • 368
  • 2
  • 10
0

update

Say, you want to send report by mail. your first report is in report1.html file. you want to send this report. say, you are using a php file named sendReport.php to sending email.

now, send a parameter in your file like this :

yourhost.com/sendReport.php?file=report1.html

in your sendReport.php get file name like this:

$fileName = $_GET['file'];

then get report html like this:

$html = file_get_contents($fileName);

then send your mail with report which is in $html

for every report file just pass right report file name in your url like this: yourhost.com/sendReport.php?file=your_file_name.html
I think it makes sense!

EDIT:

You should send a parameter for file name in your url like this:

yoursite.com?file=your_html_file_name

then in your mail sending page get file name:

$fileName = $_GET['file'];

then get report html like this:

$html = file_get_contents($fileName);

then send your mail

Awlad Liton
  • 9,366
  • 2
  • 27
  • 53