Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 598
  • Last Modified:

send the output of the script as an mail

Hi Experts
i have a script that print to the screen or html output reports please see the picture ..
and i have a table with for each customer has his email
after each end of customer in my while loop i want to mail it to the email address i have in my data
<?php
include('db.php');
?>
<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>
<html xmlns='http://www.w3.org/1999/xhtml'>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=windows-1252' />
<title>CAMPION The Power Behind The Water</title>
<?php
  if(preg_match('/(?i)msie [1-9]/',$_SERVER['HTTP_USER_AGENT'])) {
    echo " <link href='ie.css' rel='stylesheet' type='text/css' /> ";
  } else {
   echo "<link href='fire1.css' rel='stylesheet' type='text/css' />";
  }
?>

</head>
<body>
<?php
$start = date("Y-m-1", strtotime("last month"));
$end = date("Y-m-t", strtotime("last month"));  
$sql="SELECT *
     FROM count_transactions,automatic_report  
             WHERE DATE(count_transactions.tran_date) BETWEEN '$start' AND '$end' and count_transactions.account_no=automatic_report.account 
  and count_transactions.customer_no=automatic_report.customer
                AND automatic_report.periode=2  
                    GROUP BY count_transactions.customer_no order by count_transactions.account_no";  
 
           
          $res = mysql_query($sql) or die("FAIL: $sql<br>" . mysql_error());
         $num = mysql_num_rows($result1);
          while($rows = mysql_fetch_array($res)) { 
              $tot1=0;
              $tot22=0;
              $tot33=0;
              $tot44=0;
              $general1=0;
              $dateb =$rows['tran_date'];
              $dateb1=date('d-m-Y',strtotime($dateb));             
              $i=0; 
              $netw=$rows['unit_serial'];
              $client=$rows['customer_no'];
              $auto=$rows['account_no'];
              $channel=$rows['pulse_channel'];
?>
<table id ='table4'><tr>
<?php
 
$q1="SELECT unitName FROM net_watch_units WHERE serial_no=$netw";
                   $res1=mysql_query($q1);
                   $r1=mysql_fetch_array($res1);
                   $account=$r1['unitName']; 
$q2="SELECT account_name FROM account_details WHERE auto_id=$auto";
                   $res2=mysql_query($q2);
                   $r2=mysql_fetch_array($res2);
                   $name=$r2['account_name'];  

$q3="SELECT customer_name FROM customer_details WHERE auto_id=$client";
                   $res3=mysql_query($q3);
                   $r3=mysql_fetch_array($res3);
                   $name1=$r3['customer_name'];  

?> 
<?php
$query1="select account_ref,serial_no,pulser1_name,pulser2_name,pulser3_name,pulser4_name from net_watch_units
         where serial_no=$netw ";
$result2=mysql_query($query1);
$record2=mysql_fetch_array($result2);
$pulser1=$record2['pulser1_name'];  
$pulser2=$record2['pulser2_name'];
$pulser3=$record2['pulser3_name'];
$pulser4=$record2['pulser4_name'];
if(empty($pulser1) and empty($pulser2) and empty($pulser3) and empty($pulser4)){

?> 
  <input type="button"  onclick="history.go(-1);" value="No Channels please go Back">
<?php  
 exit; 
} 
if($pulse[0]=='1' && $pulse[1]=='2' && $pulse[2]=='3' && $pulse[3]=='4'){
   $chane1=$pulser1; 
   $chane2=$pulser2; 
   $chane3=$pulser3; 
   $chane4=$pulser4;  

} 
if($pulse[0]=='1' && $pulse[1]=='' && $pulse[2]=='' && $pulse[3]==''){
    
   $pulser2=''; 
   $pulser3=''; 
   $pulser4='';  

}  
if($pulse[0]=='' && $pulse[1]=='2' && $pulse[2]=='' && $pulse[3]==''){
   $pulser1=''; 
    
   $pulser3=''; 
   
   $pulser4='';  

}  
if($pulse[0]=='' && $pulse[1]=='' && $pulse[2]=='3' && $pulse[3]==''){
   $pulser1=''; 
   $pulser2='';
   $pulser4='';  
    
}  
if($pulse[0]=='' && $pulse[1]=='' && $pulse[2]=='' && $pulse[3]=='4'){
   $pulser1=''; 
   $pulser2='';
   $pulser3=''; 
   

}  
?>    
<td rowspan="2" style="width:30%"><img src='campion.png' alt='The Power Behind The Water'/></td>
<td colspan="2" style=" width:20%;font-size:14px;">Unit Name : <b><br><?php echo $account;?></b></td> 
<td colspan="2" style=" width:20%;font-size:14px;">Account Name : <b><br><?php echo $name;?></b></td> 
<td colspan="2" style=" width:15%;font-size:14px;">Customer Name : <b><br><?php echo $name1;?></b></td></tr>

<td style="font-size:12px;width:10%;">Report Date : <b><br><?php echo $dateb1;?></b></td> 
<?php
         if($report=='1'){
            $rep='Litres';
         }
         if($report=='2'){
            $rep='M3';
         }
         if($report=='3'){
            $rep='Gallons (Imp)';
         }
    
         ?>
<td style="width:10%;font-size:14px;">Report Units : <b><br><?php echo $rep;?></b></td><td colspan="3" style="font-size:14px;">Report Name : <b><br> Daily Totals Usage Report</b></td> 
</tr>
</table>

<table class='table2'> 
  <thead>
<tr>
      <th id="fr" scope="col">Date</th>   
     
      <th id="fn" scope="col"><?php echo $pulser1;?></th>  
   
         <th id="fn" scope="col"><?php echo $pulser2;?></th>  
       
        <th id="fn" scope="col"><?php echo $pulser3;?></th>  
       
         <th id="fn" scope="col"><?php echo $pulser4;?></th>  
        
       <th id="fr" scope="col">Total</th>  
    </tr>
  </thead> 
  <?php
 
 
         if($report=='1'){
            $rep='Litres';
         }
         if($report=='2'){
            $rep='M3';
         }
         if($report=='3'){
            $rep='Gallons (Imp)';
         }
$pdf="SELECT DATE(count_transactions.tran_date) as datei,
      SUM(case when count_transactions.pulse_channel = 1 then unit_qty else 0 end) as name1,
      SUM(case when count_transactions.pulse_channel = 2 then unit_qty else 0 end) as name2,
      SUM(case when count_transactions.pulse_channel = 3 then unit_qty else 0 end) as name3,
      SUM(case when count_transactions.pulse_channel = 4 then unit_qty else 0 end) as name4,
      SUM(count_transactions.unit_qty) as Total
from count_transactions,automatic_report  
WHERE  DATE(count_transactions.tran_date) BETWEEN '$start' AND '$end'   
  and count_transactions.account_no=automatic_report.account 
  and count_transactions.customer_no=automatic_report.customer
                AND automatic_report.periode=2 and count_transactions.unit_serial=$netw                                 
GROUP BY DATE(count_transactions.tran_date)";
$result=mysql_query($pdf) or die('Could not connect: ' . mysql_error());
$num=mysql_num_rows($result);
while($row= mysql_fetch_array($result)){
    $jour = $row['datei'];
    $jour=date('d-m-Y',strtotime($jour));
    $total = $row['Total'];
    $name1 = $row['name1'];
    $name2 = $row['name2'];
    $name3 = $row['name3'];
    $name4 = $row['name4']; 
if($report==2){
             $name1=$name1/1000;
             $name2=$name2/1000;
             $name3=$name3/1000;
             $name4=$name4/1000;
             $total=$total/1000; 
          }
          elseif($report==3){
              $name1=$name1*0.2199;
              $name2=$name2*0.2199;
              $name3=$name3*0.2199;
              $name4=$name4*0.2199;
              $total=$total*0.2199;   
          }
          else{
            $name1=$name1*1;
            $name2=$name2*1;
            $name3=$name3*1;
            $name4=$name4*1;
            $total=$total*1; 
          }
$namef1=str_pad(number_format($name1,2,'.',','),$imax, $pad,  STR_PAD_LEFT);
$namef2=str_pad(number_format($name2,2,'.',','),$imax, $pad,  STR_PAD_LEFT);
$namef3=str_pad(number_format($name3,2,'.',','),$imax, $pad,  STR_PAD_LEFT);
$namef4=str_pad(number_format($name4,2,'.',','),$imax, $pad,  STR_PAD_LEFT);
$totalf=str_pad(number_format($total,2,'.',','),$imax, $pad,  STR_PAD_LEFT); 
$tot1=$tot1+$name1; 
$tot22=$tot22+$name2;
$tot33=$tot33+$name3;
$tot44=$tot44+$name4; 
$general1=$general1+$total;
$somme1=str_pad(number_format($tot1),$imax,  $pad,  STR_PAD_LEFT); 
$somme2=str_pad(number_format($tot22),$imax, $pad,  STR_PAD_LEFT); 
$somme3=str_pad(number_format($tot33),$imax, $pad,  STR_PAD_LEFT); 
$somme4=str_pad(number_format($tot44),$imax, $pad,  STR_PAD_LEFT); 
$general=str_pad(number_format($general1,2,'.',','),$imax, $pad,  STR_PAD_LEFT);
if(empty($pulser1)){
   $somme1='';   
   $namef1='';
    
}
if(empty($pulser2)){
   $somme2='';   
    $namef2='';
    
}
if(empty($pulser3)){
   $somme3='';   
    $namef3='';
    

}
if(empty($pulser4)){
    $somme4='';   
    $namef4='';
    $name4=0;
   
}
$i++;
echo"<tr>"; 
       	echo"<td>$jour</td><td>$namef1</td><td>$namef2</td><td>$namef3</td><td>$namef4</td><td>$totalf</td>";
}        


 
  $av1=round($tot1/($i),2); 
  $av2=round($tot22/($i),2);
  $av3=round($tot33/($i),2); 
  $av4=round($tot44/($i),2);  
  $avg=$av1+$av2+$av3+$av4;
  $av1=str_pad(number_format($av1,2),$imax, $pad,  STR_PAD_LEFT);
  $av2=str_pad(number_format($av2,2),$imax, $pad,  STR_PAD_LEFT);
  $av3=str_pad(number_format($av3,2),$imax, $pad,  STR_PAD_LEFT);
  $av4=str_pad(number_format($av4,2),$imax, $pad,  STR_PAD_LEFT);
  
  $avg1=str_pad(number_format($avg,2),$imax, $pad,  STR_PAD_LEFT); 


?>

<tr>
<td id='td1'>Total </td>  
<td id='td1'><?php echo $somme1;?></td> 
<td id='td1'><?php echo $somme2;?></td>
<td id='td1'><?php echo $somme3;?></td>
<td id='td1'><?php echo $somme4;?></td>
<td id='td1'><?php echo $general;?></td></tr>
<?php
if(empty($pulser1)){
   $av1='';   
   
}
if(empty($pulser2)){
   $av2='';   
   
}
if(empty($pulser3)){
   $av3='';   
   
}
if(empty($pulser4)){
   $av4='';   
   
}
?>
<tr>
<td id='td1'>Daily Average </td> 
<td id='td1'><?php echo $av1;?></td> 
<td id='td1'><?php echo $av2;?></td> 
<td id='td1'><?php echo $av3;?></td> 
<td id='td1'><?php echo $av4;?></td> 
<td id='td1'><?php echo $avg1;?></td> 
</tr></table> 
 

<p><img src='litre.php?start=<?php echo $start?>&end=<?php echo $end?>&netw=<?php echo $netw?>&auto=<?php echo $auto?>'/></p> 
</tr></table> 
<?php 
} 
if($num>0){

?>
<input type="button" id="BTNPRINT" value="Print" onClick="window.print();"> 
<input type="button" id="BTNPRINT"onclick="window.location.href='export.php?date=<?php echo $date?>&date2=<?php echo $date2?>&netw=<?php echo $netw?>'" value='Export'>
<?php

}
else{
echo "<h2> No Data Found...</h2>"; 
echo "<br>";

?>
<input type="button"  onclick="history.go(-1);" value="Back">
<?php
}

$url="http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
echo $url;
?>
</body>
</html>    

Open in new window

ex.jpg
0
asaidi
Asked:
asaidi
  • 17
  • 10
  • 7
3 Solutions
 
Mohamed AbowardaSoftware EngineerCommented:
ob_get_clean() will return the output buffer and clean the output:
http://php.net/manual/en/function.ob-get-clean.php

ob_get_clean() essentially executes both ob_get_contents() and ob_end_clean().

You can then email the output using mail() method.
0
 
gr8gonzoConsultantCommented:
To expand on what Medo3337 was saying, the output buffer is basically a way to make PHP store all the output into a hidden variable/buffer until you tell it what to do with the buffer. So you would start the buffer on each loop, and at the end of the loop, you'd get all the contents with ob_get_clean();, echo it to the screen, and then mail it out:

while($rows = mysql_fetch_array($res)) {

   // Start the output buffer
   ob_start();

   ... your current code...

   // At the end of the loop, finish the buffer and get the contents.
   $output = ob_get_clean();

   // Display it on the screen like normal
   echo $output;

   // Mail it, too
   mail("you@somewhere.com","Output for Client: $client",$output);
}
0
 
asaidiAuthor Commented:
Hi gr8gonzo
thanks
then all the html like <table> or <p>
i need to put into an echo
like this
<tr>
<td id='td1'>Total </td>  
<td id='td1'><?php echo $somme1;?></td>
<td id='td1'><?php echo $somme2;?></td>
<td id='td1'><?php echo $somme3;?></td>
<td id='td1'><?php echo $somme4;?></td>
<td id='td1'><?php echo $general;?></td></tr>
i put it under an echo
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
gr8gonzoConsultantCommented:
No, you don't need to put anything into an echo or print. When the output buffer is on, ALL script output gets captured from the point that it is turned on until the point it is turned off.
0
 
gr8gonzoConsultantCommented:
You shouldn't need to make any script changes outside of putting ob_start() above the code in the loop and the ob_get_clean(), echo, and mail lines that I proposed:

while($rows = mysql_fetch_array($res)) {
   ob_start();
   ... your current UNCHANGED code...
   $output = ob_get_clean();
   echo $output;
   mail("you@somewhere.com","Output for Client: $client",$output);
}
0
 
asaidiAuthor Commented:
yes but when i put this in my code all the table is stretched ..
0
 
gr8gonzoConsultantCommented:
Is it stretched in the email or in the browser?
0
 
asaidiAuthor Commented:
no in the browser..i did not try it in email
0
 
gr8gonzoConsultantCommented:
Is there a URL where we can see the output?

The output buffer should not change the contents at all, so if something is changing, there may be an error somewhere or an issue with the HTML.
0
 
asaidiAuthor Commented:
hi
that is what i get in my email is it correct
<tr><td>01-07-2012</td><td>0.00</td><td></td><td></td><td></td><td>0.00</td>
<tr>
<td id='td1'>Total </td>
<td id='td1'>0</td>
<td id='td1'></td>
<td id='td1'></td>
<td id='td1'></td>
<td id='td1'>0.00</td></tr>
<tr>
<td id='td1'>Daily Average </td>
<td id='td1'>0.00</td>
<td id='td1'></td>
<td id='td1'></td>
<td id='td1'></td>
<td id='td1'>0.00</td>
</tr></table>


<p><img src='litre.php?start=2012-07-1&end=2012-07-31&netw=13&auto=1'/></p>
</tr></table>
http://localhost:8080/campion/css2/monthly.php<input type="button" id="BTNPRINT" value="Print" onClick="window.print();">
<input type="button" id="BTNPRINT"onclick="window.location.href='export.php?date=&date2=&netw=13'" value='Export'>

Open in new window

0
 
gr8gonzoConsultantCommented:
It looks like your loops are closing  tables that they have not opened. This might be why your tables look stretched - they are malformed.

You should always have something like this:

while(something)
{
    ?>
   <table>
     ... table contents ...
   </table>
   <?php
}

What you have is:

while(something)
{
    ?>
   <table>

    <?php
    while(something else)
    {
        ?>
        ... table contents ...
        </table>    
   <?php
    }
}

The result is that you end up with HTML like:

<table>
</table>
</table>

The browser has a hard time understanding and rendering it. You need to go back through your code and make sure that your loops are only closing tables that they have opened. It may help to indent your code more in each loop.
0
 
Mohamed AbowardaSoftware EngineerCommented:
You use echo() to print the HTML on the page, you should use a variable instead of echo() to store the HTML and email it using mail().

You don't even need to use echo() as I see in your code, instead store the output in a variable.
0
 
gr8gonzoConsultantCommented:
Also, once you get the browser looking right, you'll need to adjust the mail() function a bit to send HTML mail instead:

mail("you@somewhere.com","Output for Client: $client","<html><body>$output</body></html>","MIME-Version: 1.0\r\nContent-type: text/html; charset=iso-8859-1\r\n");
0
 
gr8gonzoConsultantCommented:
@Medo - that is not accurate. The output buffer will capture the output. He does not need to store it into a variable.
0
 
Mohamed AbowardaSoftware EngineerCommented:
@gr8gonzo: What I mean is that If I want to build contents to email it, I would use a variable like following:
$contents = 'any contents here';
// Other codes
$contents += 'more contents here...';
// More code
$contents += 'more contents...';

mail('Put email address here', 'Put subject here', $contents, 'Any additional header...');

Open in new window

0
 
gr8gonzoConsultantCommented:
But why suggest a separate variable when output buffer will create that variable for him? You were even the first one to correctly suggest the output buffer. :) I was just agreeing with your first suggestion and clarifying the code.
0
 
Mohamed AbowardaSoftware EngineerCommented:
Output buffer is a way to go, however, If I were him, I would use a variable instead, if I want to output the contents as well I can simply use:
echo $contents;

Open in new window


Generally, you have better control over a variable.

Also, remember, using LOOP with sending email might spam your email if the loop kept looping in error or the loop kept sending many emails.
0
 
asaidiAuthor Commented:
Hi
in email how i can see it
      Unit Name :
Bulk Meter Upper Coolgreany      Account Name :
Castlewarren GWS      Customer Name :
Ballycumber
Report Date :
01-07-2012      Report Units :
Report Name :
Daily Totals Usage Report
Date      Bulk Meter Upper Coolgreany                        Total
01-07-2012      0.00                        0.00
Total      0                        0.00
Daily Average       0.00                        0.00


      Unit Name :
Reservoir Unit 1      Account Name :
Castlewarren GWS      Customer Name :
LiamBrettAccess
Report Date :
01-07-2012      Report Units :
Report Name :
Daily Totals Usage Report
Date      Reservoir Meter 1      Reservoir Meter 2      Reservoir Meter 3            Total
01-07-2012      0.00      0.00      40.00            40.00
Total      0      0      40            40.00
Daily Average      0.00      0.00      40.00            40.00


http://localhost:8080/campion/css2/monthly.php 
and there is this link when he click on it he get a nice looking report the problem that when he clicks it send again an email..
0
 
gr8gonzoConsultantCommented:
If you don't want it to send again, you'll need to add a parameter like:

http://localhost:8080/campion/css2/monthly.php?sendEmail=0

And in the code, change the mail code to:

if(!isset($_GET["sendEmail"]) || $_GET["sendEmail"])
{
   mail("you@somewhere.com","Output for Client: $client","<html><body>$output</body></html>","MIME-Version: 1.0\r\nContent-type: text/html; charset=iso-8859-1\r\n");
}

IF you want one email for all clients, then put the the output buffer OUTSIDE the loop:

BEFORE:
while($rows = mysql_fetch_array($res)) {
   ob_start();
   ... your current UNCHANGED code...
   $output = ob_get_clean();
   echo $output;
 
   if(!isset($_GET["sendEmail"]) || $_GET["sendEmail"])
   {
      mail(...);
    }
}

AFTER:
ob_start();
while($rows = mysql_fetch_array($res)) {
   ... your current UNCHANGED code...
}
$output = ob_get_clean();
echo $output;
 
if(!isset($_GET["sendEmail"]) || $_GET["sendEmail"])
{
  mail(...);
}
0
 
asaidiAuthor Commented:
Hi
please do i need to show the user the graphic i m using in my script or he can see the graph when he clicks on the link
in my script i have this
<p><img src='graphn.php?startDate=<?php echo $startDate?>&endDate=<?php echo $endDate?>&netw=<?php echo $netw?>'/></p>
or please find attached picture of my result
graph.jpg
0
 
gr8gonzoConsultantCommented:
I'm not sure what this has to do with the original question?
0
 
asaidiAuthor Commented:
it is a part because when i get the email i can see all the html in the body of the email
if it is not a part then i can close the question by accepting the solution
0
 
gr8gonzoConsultantCommented:
What does your mail() code look like?
0
 
asaidiAuthor Commented:
i embedded in my script
<?php
include('db.php');
ob_start();  
?> 
<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>
<html xmlns='http://www.w3.org/1999/xhtml'>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=windows-1252' />
<title>CAMPION The Power Behind The Water</title>
<?php
  if(preg_match('/(?i)msie [1-9]/',$_SERVER['HTTP_USER_AGENT'])) {
    echo " <link href='ie.css' rel='stylesheet' type='text/css' /> ";
  } else {
   echo "<link href='fire1.css' rel='stylesheet' type='text/css' />";
  }
?>

</head>
<body>
<?php
$start = date("Y-m-1", strtotime("last month"));
$end = date("Y-m-t", strtotime("last month"));  
$sql="SELECT *
     FROM count_transactions,automatic_report  
             WHERE DATE(count_transactions.tran_date) BETWEEN '$start' AND '$end' and count_transactions.account_no=automatic_report.account 
  and count_transactions.customer_no=automatic_report.customer
                AND automatic_report.periode=2  
                    GROUP BY count_transactions.customer_no";  
     
          $res = mysql_query($sql) or die("FAIL: $sql<br>" . mysql_error());
         $num = mysql_num_rows($result1);
          while($rows = mysql_fetch_array($res)) { 
              $tot1=0;
              $tot22=0;
              $tot33=0;
              $tot44=0;
              $general1=0;
              $dateb =$rows['tran_date'];
              $dateb1=date('d-m-Y',strtotime($dateb));             
              $i=0; 
              $netw=$rows['unit_serial'];
              $client=$rows['customer_no'];
              $auto=$rows['account_no'];
              $channel=$rows['pulse_channel'];
              $email=$rows['email'];
?>
<table id ='table4'><tr>
<?php
 
$q1="SELECT unitName FROM net_watch_units WHERE serial_no=$netw";
                   $res1=mysql_query($q1);
                   $r1=mysql_fetch_array($res1);
                   $account=$r1['unitName']; 
$q2="SELECT account_name FROM account_details WHERE auto_id=$auto";
                   $res2=mysql_query($q2);
                   $r2=mysql_fetch_array($res2);
                   $name=$r2['account_name'];  

$q3="SELECT customer_name FROM customer_details WHERE auto_id=$client";
                   $res3=mysql_query($q3);
                   $r3=mysql_fetch_array($res3);
                   $name1=$r3['customer_name'];  

 
$query1="select account_ref,serial_no,pulser1_name,pulser2_name,pulser3_name,pulser4_name from net_watch_units
         where serial_no=$netw ";
$result2=mysql_query($query1);
$record2=mysql_fetch_array($result2);
$pulser1=$record2['pulser1_name'];  
$pulser2=$record2['pulser2_name'];
$pulser3=$record2['pulser3_name'];
$pulser4=$record2['pulser4_name'];
if(empty($pulser1) and empty($pulser2) and empty($pulser3) and empty($pulser4)){

?> 
  <input type="button"  onclick="history.go(-1);" value="No Channels please go Back">
<?php  
 exit; 
} 
if($pulse[0]=='1' && $pulse[1]=='2' && $pulse[2]=='3' && $pulse[3]=='4'){
   $chane1=$pulser1; 
   $chane2=$pulser2; 
   $chane3=$pulser3; 
   $chane4=$pulser4;  

} 
if($pulse[0]=='1' && $pulse[1]=='' && $pulse[2]=='' && $pulse[3]==''){
    
   $pulser2=''; 
   $pulser3=''; 
   $pulser4='';  

}  
if($pulse[0]=='' && $pulse[1]=='2' && $pulse[2]=='' && $pulse[3]==''){
   $pulser1=''; 
    
   $pulser3=''; 
   
   $pulser4='';  

}  
if($pulse[0]=='' && $pulse[1]=='' && $pulse[2]=='3' && $pulse[3]==''){
   $pulser1=''; 
   $pulser2='';
   $pulser4='';  
    
}  
if($pulse[0]=='' && $pulse[1]=='' && $pulse[2]=='' && $pulse[3]=='4'){
   $pulser1=''; 
   $pulser2='';
   $pulser3=''; 
   

}  
?>    
<td rowspan="2" style="width:30%"><img src='campion.png' alt='The Power Behind The Water'/></td>
<td colspan="2" style=" width:20%;font-size:14px;">Unit Name : <b><br><?php echo $account;?></b></td> 
<td colspan="2" style=" width:20%;font-size:14px;">Account Name : <b><br><?php echo $name;?></b></td> 
<td colspan="2" style=" width:15%;font-size:14px;">Customer Name : <b><br><?php echo $name1;?></b></td></tr>
<td style="font-size:12px;width:10%;">Report Date : <b><br><?php echo $dateb1;?></b></td> 
<?php
         if($report=='1'){
            $rep='Litres';
         }
         if($report=='2'){
            $rep='M3';
         }
         if($report=='3'){
            $rep='Gallons (Imp)';
         }
?>
<td style="width:10%;font-size:14px;">Report Units : <b><br><?php echo $rep;?></b></td><td colspan="3" style="font-size:14px;">Report Name : <b><br> Daily Totals Usage Report</b></td> 
</tr>
</table>

<table class='table2'> 
  <thead>
<tr>
      <th id="fr" scope="col">Date</th>   
     
      <th id="fn" scope="col"><?php echo $pulser1;?></th>  
   
         <th id="fn" scope="col"><?php echo $pulser2;?></th>  
       
        <th id="fn" scope="col"><?php echo $pulser3;?></th>  
       
         <th id="fn" scope="col"><?php echo $pulser4;?></th>  
        
       <th id="fr" scope="col">Total</th>  
    </tr>
  </thead> 
  <?php
 
 
         if($report=='1'){
            $rep='Litres';
         }
         if($report=='2'){
            $rep='M3';
         }
         if($report=='3'){
            $rep='Gallons (Imp)';
         }
$pdf="SELECT DATE(count_transactions.tran_date) as datei,
      SUM(case when count_transactions.pulse_channel = 1 then unit_qty else 0 end) as name1,
      SUM(case when count_transactions.pulse_channel = 2 then unit_qty else 0 end) as name2,
      SUM(case when count_transactions.pulse_channel = 3 then unit_qty else 0 end) as name3,
      SUM(case when count_transactions.pulse_channel = 4 then unit_qty else 0 end) as name4,
      SUM(count_transactions.unit_qty) as Total
from count_transactions,automatic_report  
WHERE  DATE(count_transactions.tran_date) BETWEEN '$start' AND '$end'   
  and count_transactions.account_no=automatic_report.account 
  and count_transactions.customer_no=automatic_report.customer
                AND automatic_report.periode=2 and count_transactions.unit_serial=$netw                                 
GROUP BY count_transactions.customer_no,DATE(count_transactions.tran_date)";
$result=mysql_query($pdf) or die('Could not connect: ' . mysql_error());
$num=mysql_num_rows($result);
while($row= mysql_fetch_array($result)){
    
    $jour = $row['datei'];
    $jour=date('d-m-Y',strtotime($jour));
    $total = $row['Total'];
    $name1 = $row['name1'];
    $name2 = $row['name2'];
    $name3 = $row['name3'];
    $name4 = $row['name4']; 
if($report==2){
             $name1=$name1/1000;
             $name2=$name2/1000;
             $name3=$name3/1000;
             $name4=$name4/1000;
             $total=$total/1000; 
          }
          elseif($report==3){
              $name1=$name1*0.2199;
              $name2=$name2*0.2199;
              $name3=$name3*0.2199;
              $name4=$name4*0.2199;
              $total=$total*0.2199;   
          }
          else{
            $name1=$name1*1;
            $name2=$name2*1;
            $name3=$name3*1;
            $name4=$name4*1;
            $total=$total*1; 
          }
$namef1=str_pad(number_format($name1,2,'.',','),$imax, $pad,  STR_PAD_LEFT);
$namef2=str_pad(number_format($name2,2,'.',','),$imax, $pad,  STR_PAD_LEFT);
$namef3=str_pad(number_format($name3,2,'.',','),$imax, $pad,  STR_PAD_LEFT);
$namef4=str_pad(number_format($name4,2,'.',','),$imax, $pad,  STR_PAD_LEFT);
$totalf=str_pad(number_format($total,2,'.',','),$imax, $pad,  STR_PAD_LEFT); 
$tot1=$tot1+$name1; 
$tot22=$tot22+$name2;
$tot33=$tot33+$name3;
$tot44=$tot44+$name4; 
$general1=$general1+$total;
$somme1=str_pad(number_format($tot1),$imax,  $pad,  STR_PAD_LEFT); 
$somme2=str_pad(number_format($tot22),$imax, $pad,  STR_PAD_LEFT); 
$somme3=str_pad(number_format($tot33),$imax, $pad,  STR_PAD_LEFT); 
$somme4=str_pad(number_format($tot44),$imax, $pad,  STR_PAD_LEFT); 
$general=str_pad(number_format($general1,2,'.',','),$imax, $pad,  STR_PAD_LEFT);
if(empty($pulser1)){
   $somme1='';   
   $namef1='';
    
}
if(empty($pulser2)){
   $somme2='';   
    $namef2='';
    
}
if(empty($pulser3)){
   $somme3='';   
    $namef3='';
    

}
if(empty($pulser4)){
    $somme4='';   
    $namef4='';
    $name4=0;
   
}
$i++;
echo"<tr>"; 
       	echo"<td>$jour</td><td>$namef1</td><td>$namef2</td><td>$namef3</td><td>$namef4</td><td>$totalf</td>";
}        


 
  $av1=round($tot1/($i),2); 
  $av2=round($tot22/($i),2);
  $av3=round($tot33/($i),2); 
  $av4=round($tot44/($i),2);  
  $avg=$av1+$av2+$av3+$av4;
  $av1=str_pad(number_format($av1,2),$imax, $pad,  STR_PAD_LEFT);
  $av2=str_pad(number_format($av2,2),$imax, $pad,  STR_PAD_LEFT);
  $av3=str_pad(number_format($av3,2),$imax, $pad,  STR_PAD_LEFT);
  $av4=str_pad(number_format($av4,2),$imax, $pad,  STR_PAD_LEFT);
  
  $avg1=str_pad(number_format($avg,2),$imax, $pad,  STR_PAD_LEFT); 


?>

<tr>
<td id='td1'>Total </td>  
<td id='td1'><?php echo $somme1;?></td> 
<td id='td1'><?php echo $somme2;?></td>
<td id='td1'><?php echo $somme3;?></td>
<td id='td1'><?php echo $somme4;?></td>
<td id='td1'><?php echo $general;?></td></tr>
<?php
if(empty($pulser1)){
   $av1='';   
   
}
if(empty($pulser2)){
   $av2='';   
   
}
if(empty($pulser3)){
   $av3='';   
   
}
if(empty($pulser4)){
   $av4='';   
   
}
?>
<tr>
<td id='td1'>Daily Average </td> 
<td id='td1'><?php echo $av1;?></td> 
<td id='td1'><?php echo $av2;?></td> 
<td id='td1'><?php echo $av3;?></td> 
<td id='td1'><?php echo $av4;?></td> 
<td id='td1'><?php echo $avg1;?></td> 
</tr></table> 
 

<p><img src='litre.php?start=<?php echo $start?>&end=<?php echo $end?>&netw=<?php echo $netw?>&auto=<?php echo $auto?>'/></p> 
</tr></table> 
<?php 
 
 $output = ob_get_clean();
   echo $output; 
   mail($email,"Output for Client: $name1","<html><body>$output</body></html>","MIME-Version: 1.0\r\nContent-type: text/html; charset=iso-8859-1\r\n"); 
 }
  
if($num>0){
$url="http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
echo $url;


?>


<input type="button" id="BTNPRINT" value="Print" onClick="window.print();"> 
<input type="button" id="BTNPRINT"onclick="window.location.href='export.php?date=<?php echo $date?>&date2=<?php echo $date2?>&netw=<?php echo $netw?>'" value='Export'>
<?php
}
else{
echo "<h2> No Data Found...</h2>"; 
echo "<br>";
?>
<input type="button"  onclick="history.go(-1);" value="Back">
<?php

 


}
?>
</body>
</html>    
look at line306

Open in new window

0
 
gr8gonzoConsultantCommented:
Well, your ob_start() is a little too far up. It should probably be on line 21 or so. But still, that shouldn't keep it from working. If you're seeing HTML code, then that means that your email reader is not displaying the HTML contents correctly. I just tested your code on my system using Mozilla THunderbird to view the email and it came across just fine.

Now, when someone is reading your email message, they are viewing plain HTML that has been generated and saved and copied into an email message. They are not viewing that code from your web site, so if your HTML makes a relative reference to a chart image or CSS file or anything:

<img src="chart.php">

...then they are not going to see the chart because the mail reader will be looking on the reader's computer for chart.php and will not see it. You can use an absolute reference, like this:

<img src="http://www.yourdomain.com/path/to/chart.php">

...and that will work (although the reader will probably have to click a button to allow their program to display the image - it is a safety measure that cannot be disabled).

You can also embed the images, but that is a lot more complicated and can lead to large emails being sent out. It is not advisable.
0
 
asaidiAuthor Commented:
please explain me how i can divide between the answers sorry it was a mistake..normally i must share the points
0
 
gr8gonzoConsultantCommented:
I'd suggest splitting it up equally among 3 answers:

http:#a38315247 - Initial ob_get_clean() suggestion
http:#38316457 - Code, structure, and mail command
http:#38323461 - Final sub question
0
 
asaidiAuthor Commented:
but how i do this
0
 
Mohamed AbowardaSoftware EngineerCommented:
Hi,

A moderator should now re-open the question or change the accepted answer, I would think my answer should take the most points since I posted the main answer and other comments was clarification according to my answer.
0
 
gr8gonzoConsultantCommented:
@Medo - I would disagree with that. There were multiple questions. ob_get_clean() may have been one of the functions used, but it's useless without ob_start() or how / where to use it. I addressed the majority of the question and all the sub-questions.
0
 
Mohamed AbowardaSoftware EngineerCommented:
@gr8gonzo:
I was the first to mention ob_ family, you always need to use ob_start(), even the asker said that he wanted to split points but he don't know how #38325513
0
 
gr8gonzoConsultantCommented:
I know - and per my comment  38325577, I suggested your first comment as one of the three answers to accept.
0
 
gr8gonzoConsultantCommented:
I tried to suggest the 3 different answers that (when put together) fully addressed the overall question. I wasn't trying to take all the points - just trying to be accurate in what comments actually seemed to be the ones that made up the final, full answer.
0
 
Mohamed AbowardaSoftware EngineerCommented:
I think the asker should take the appropriate action, and since he didnt know how to split points, the question should be re-opened.
0

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

  • 17
  • 10
  • 7
Tackle projects and never again get stuck behind a technical roadblock.
Join Now